解题思路:本质就是对函数的运用
注意事项:公式别写错
参考代码:
#include <stdio.h> #include <stdlib.h> #include <math.h> void dayu(double a, double b, double c); void xiaoyu(double a, double b,double c); void dengyu(double a, double b); int main(void) { double a, b, c; scanf("%lf %lf %lf", &a, &b, &c); if (b * b - 4 * a * c > 0) dayu(a, b, c); if (b * b - 4 * a * c < 0) xiaoyu(a,b,c); if (b * b - 4 * a * c == 0) dengyu(a, b); return 0; } void dayu(double a, double b, double c) { double x1, x2; x1 = (pow((-b + (b * b - 4 * a * c)),(1.0 / 2))) / 2 * a; x2 = (pow((-b - (b * b - 4 * a * c)), (1.0 / 2))) / 2 * a; printf("x1=%lf x2=%lf", x1, x2); } void xiaoyu(double a , double b,double c) { printf("x1=%.3lf+%.3lfi ", -b / (2 * a), sqrt(4 * a * c - b*b) / (2 * a)); //x=(-b± i√(4ac-b²))/(2a) printf("x2=%.3lf-%.3lfi", -b / (2 * a), sqrt(4 * a * c - b*b) / (2 * a)); } void dengyu(double a, double b) { double x1, x2; x1 = -b / (2 * a); x2 = x1; printf("x1=%.3lf x2=%.3lf", x1, x2); }
0.0分
5 人评分
x1 = (-b+pow((b * b - 4 * a * c),(1.0 / 2))) / 2 * a; //x1 =(-b+(b*b-4ac)^(1/2))/2a; x2 = (-b-pow((b * b - 4 * a * c), (1.0 / 2))) / 2 * a; //x2 =(-b-(b*b-4ac)^(1/2))/2a; 我就想知道为啥不是我这个样子; (^ .. ^)
#include<stdio.h> #include<math.h> void fun1(float a,float b,float c) { double s; s=sqrt(b*b-4*a*c); printf("x1=%.3f x2=%.3f",(-b+s)/2/a,(-b-s)/2/a); } void fun2(float a,float b,float c) { fun1(a,b,c); } void fun3(float a,float b,float c) { double s; s=sqrt(4*a*c-b*b); printf("x1=%.3f+%.3fi x2=%.3f-%.3fi",-b/a/2,s/2/a,-b/a/2,s/2/a); } int main() { float a,b,c; scanf("%f%f%f",&a,&b,&c); if(b*b-4*a*c>0)fun1(a,b,c); else if(b*b-4*a*c==0)fun2(a,b,c); else fun3(a,b,c); return 0; }//比较傻的方法
请问x1 = (pow((-b + (b * b - 4 * a * c)),(1.0 / 2))) / 2 * a; 中(1.0 / 2)是为什么
扣脚的菜鸟 2021-04-28 14:07:43 |
我查了一下 pow(x,y)//求x的y次方,可是 b^2-4ac>0 的公式好像不是pow((-b + (b * b - 4 * a * c)),(1.0 / 2))这个,为什么?
为啥有些点3有些不点3 麻烦指导一下谢谢
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:941 |
Pascal三角 (C语言代码)格式错误浏览:551 |
【蟠桃记】 (C语言代码)浏览:697 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:638 |
1011题解浏览:819 |
1118(求助_已解决)浏览:351 |
单词个数统计 (C语言代码)浏览:1046 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:812 |
矩阵转置 (C语言代码)浏览:855 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:1108 |