关于ax2+bx+c=0的根问题
各位好:我在看小甲鱼C语言视频的时候有这样一道题目:
然后这是我的主程序:
double a,b,c,p,q,x1,x2;
scanf("a=%lf,b=%lf,c=%lf",&a,&b,&c);
p = (-1.0*b)/(2.0*a);
q = sqrt(b*b-4.0*a*c)/(2.0*a);
x1 = p+q;
x2 = p-q;
printf("q = %5.2lf\n x1 = %5.2lf\n x2 = %5.2lf\n",q,x1,x2);
会报错 错误结果是:
#include<math.h>加没加 雪C 发表于 2015-6-1 18:55
#include加没加
加了的,实在头文件include里面呢!!! 简单粗暴直接上代码,自己看着解决吧,程序正确性没验证,只是根据你的代码改的。
#include<stdio.h>
#include<math.h>
void main()
{
double a,b,c,p,q,x1,x2;
/*
scanf("a= %lf,b= %lf,c= %lf",&a,&b,&c);
*/
printf("a=");
scanf("%lf",&a);
printf("b=");
scanf("%lf",&b);
printf("c=");
scanf("%lf",&c);
p = (-1.0*b)/(2.0*a);
q = sqrt(b*b-4.0*a*c)/(2.0*a);
x1 = p+q;
x2 = p-q;
printf("q = %5.2lf\n x1 = %5.2lf\n x2 = %5.2lf\n",q,x1,x2);
}
啦啦啦 具体哪个地方报错 你可以写出来 那样大神们方便为你改啊
页:
[1]