#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,x1,x2;
scanf("%d%d%d",&a,&b,&c);
int D = b*b -4*a*c;
if(D<0){
printf("No real root\n");
}else{
x1 = (-b + sqrt(D)) /2*a;
x2 = (-b - sqrt(D)) /2*a;
if(D == 0){
printf("Two same roots x=%d\n",x1);
}else {
int t;
if(x1 < x2){
t = x1;
x1 = x2;
x2 = t;
}
printf("Two different roots x1=%d , x2=%d\n",x1,x2);
}
}
return 0;
}
#include
#include
int main()
{
int a,b,c,x1,x2;
scanf("%d%d%d",&a,&b,&c);
int D = b*b -4*a*c;
if(D<0){
printf("No real root\n");
}else{
x1 = (-b + sqrt(D)) /2*a;
x2 = (-b - sqrt(D)) /2*a;
if(D == 0){
printf("Two same roots x=%d\n",x1);
}else {
int t;
if(x1 < x2){
t = x1;
x1 = x2;
x2 = t;
}
printf("Two different roots x1=%d , x2=%d\n",x1,x2);
}
}
return 0;
}
x1 = (-b + sqrt(D)) /(2*a);
x2 = (-b - sqrt(D)) /(2*a);
應概要加括號
不然就變成是最後才在成一個a