求助c语言高手

[复制链接]
查看11 | 回复2 | 2008-8-18 19:03:51 | 显示全部楼层 |阅读模式
#include
void main()
{
double a,b,c,x1,x2,real_part,imag_part,delt;

printf("Enter a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
printf("The equation ");
if(fabs(a)1e-6)

{x1=(-b+sqrt(delt))/(2*a);

x2=(-b-sqrt(delt))/(2*a);

printf("has distinct real roots: %7.2 and %7.2\n",x1,x2);}

else
{real_part=-b/(2*a);

imag_part=sqrt(-delt)/(2*a);

printf("has complex roots:\n");

printf("%7.2+%7.2i\n",real_part,imag_part);

printf("%7.2-%7.2i\n",real_part,imag_part);}}}
}
执行过程有问题
无论输入的a,b,c为多少,
得到的都是复数根。

回复

使用道具 举报

千问 | 2008-8-18 19:03:51 | 显示全部楼层
我将你的代码看了一下,导致错误的愿意可能是由于你粗心没有看清楚吧,#include \*输入输出标注函数一定要记得,否则你的终端操作白忙了*\#includevoid main() {double a,b,c,x1,x2,real_part,imag_part,delt;printf("Enter a,b,c:");scanf("%f,%f,%f",&a,&b,&c); printf("The equation ");if(fabs(a)<=1e-6)\*这句之前你多加了个花括号*\ printf("is not a quadratic\n")...
回复

使用道具 举报

千问 | 2008-8-18 19:03:51 | 显示全部楼层
printf("has two equal roots: %7.2\n",-b/(2*a)); 改为printf("has two equal roots: %7.2f\n",-b/(2*a)); printf("has distinct real roots: %7.2 and %7.2\n",x1,x2);}改为printf("h...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行