a006.
一元二次方程式
| From: [220.142.70.87] |
發表日期
:
2018-05-27 10:58
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,c,x1,x2;
while(scanf("%d %d %d",&a,&b,&c)!=EOF)
{
if((b*b-4*a*c)>0)
{
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
if(x1>x2)
{
printf("Two different roots x1=%d , x2=%d\n",x1,x2);
}
else
{
printf("Two different roots x1=%d , x2=%d\n",x2,x1);
}
}
else if((b*b-4*a*c)==0)
{
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
printf("Two same roots x=%d\n",x1);
}
else if((b*b-4*a*c)<0)
{
printf("No real root\n");
}
}
return 0;
}