求ax^2+bx+c=0的根如何编程 请问下面哪错了

[复制链接]
查看11 | 回复1 | 2009-5-7 09:08:24 | 显示全部楼层 |阅读模式
#include"math.h"
main()
{float a,b,c,d,m,n,root1,root2;
printf("input a,b,c:");
scanf("%f,%f,%f",a,b,c);
if(a==0&&b==0)
if(c==0)

printf("It has infinite roots\n");
else printf("It is rootless!\n");
else if(a==0&&b!=0)
printf("It has a single root:%.2f\n",-c/b);
else
{d=b*b-4*a*c;
m=-b/(2*a);
n=sqrt(fabs(d))/(2*a);
if(d>0)
{root1=m+n;
root2=m-n;
printf("It has two different roots:%.2f,%.2f\n",root1,root2);
}
else
{printf("root1=%.2f+%.2fi\n",m,n);
printf("root2=%.2f-%.2fi\n",m,n);
}
}
}

回复

使用道具 举报

千问 | 2009-5-7 09:08:24 | 显示全部楼层
scanf("%f,%f,%f",&a,&b,&c);...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行