c语言c 一元二次方程,C语言计算一元二次方程的根。

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(

我要举报

如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!

大家都在看

推荐资讯

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值