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