C语言计算一元二次方程的根。
答案:4 信息版本:手机版
解决时间 2019-10-06 23:22
已解决
2019-10-06 04:23
求指出错误
#include #include int main(void)
{
float a, b, c, d, x1, x2;
char ans;
printf("Enter the coefficients of the quadratic equation>");
scanf("%f\t%f\t%f", &a, &b, &c);
if(a !=0 && d >=0)
{
d=pow(b,2)-4*a*c;
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f\tx2=%f", x1, x2);
printf("Do you want to solve another quadratic equation(y/n)?>");
fflush(stdin);
scanf("%c", &ans);
}
else
{
prinft("wrong");
}
return(0);
}
gcc -lm 1.c 之后
出现如下问题
看不懂
Undefined first referenced
symbol in file
prinft /var/tmp//ccEWqWlc.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
求解 谢谢
最佳答案
2019-10-06 05:27
#include #include int main()
{
float a, b, c;
double d, x1, x2;
printf("Enter the coefficients of the quadratic equation>\n");
while(scanf("%f\t%f\t%f", &a, &b, &c)!=EOF)
{
double d;
d=pow(b,2)-4*a*c;
if((a!=0&&d>=0)!=EOF)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%lf\tx2=%lf\n", x1, x2);
}
printf("Enter the coefficients of the quadratic equation>\n");
}
return 0;
}
全部回答
1楼
2019-10-06 07:15
#include "stdio.h"
#include "math.h"
#include "windows.h"
void main()
{
float a,b,c;
printf("----计算一元二次方程 ax^2+bx+c=0的根----\n");
printf("请输入a,b,c的值: ");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
{
printf("该方程不是一元二次方程!\n");
return;
}
float t=b*b-4*a*c;
if(t>0)
{
printf("x1=%f\nx2=%f\n",(-b+sqrt(t))/(2*a),(-b-sqrt(t))/(2*a));
}
else if(t==0)
printf("x1=%f\nx2=%f\n",(-b)/(2*a),(-b)/(2*a));
else
printf("没有实数根\n");
system("pause");
return ;
}
2楼
2019-10-06 07:02
if(a !=0 && d >=0)
{
d=pow(b,2)-4*a*c;
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
这里 还没有给d进行赋值就先对d>=0进行了判断所以错了,改成:
d=pow(b,2)-4*a*c;
if(a !=0 && d >=0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
就行了
3楼
2019-10-06 06:43
void root2(double a,double b,double disc); //定义方程有两个根时的//一元二次方程二次项系数不为0 { printf(
我要举报
如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
大家都在看
推荐资讯