#include<stdio.h>
#include<math.h>
int main () {
int a,b,c,s,x,y;
scanf("%d %d %d",&a,&b,&c);
s = (b*b) - (4*a*c);
x = (-b + sqrt(s))/2*a;
y = (-b - sqrt(s))/2*a;
if(s > 0) {
printf("Two different roots x1=%d , x2=%d",x,y);
}
if(s == 0 && x == y) {
printf("Two same roots x=%d",-b/(2*a));
}
if(s < 0) {
printf("No real root");
}
return 0;
}
#include
#include
int main () {
int a,b,c,s,x,y;
scanf("%d %d %d",&a,&b,&c);
s = (b*b) - (4*a*c);
x = (-b + sqrt(s))/2*a;
y = (-b - sqrt(s))/2*a;
if(s > 0) {
printf("Two different roots x1=%d , x2=%d",x,y);
}
if(s == 0 && x == y) {
printf("Two same roots x=%d",-b/(2*a));
}
if(s < 0) {
printf("No real root");
}
return 0;
}
大神 問一下 我打的為什麼不行過@@?
#include<stdio.h>
#include<math.h>
int main() {
int a, b, c, x1, x2;
scanf("%d %d %d", &a, &b, &c);
double 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", x1, x2);
} else if (d == 0) {
x1 = (-b) / 2 * a;
printf("Two same roots x=%d", x1);
} else {
printf("No real root");
}
return 0;
}
#include
#include
int main () {
int a,b,c,s,x,y;
scanf("%d %d %d",&a,&b,&c);
s = (b*b) - (4*a*c);
x = (-b + sqrt(s))/2*a;
y = (-b - sqrt(s))/2*a;
if(s > 0) {
printf("Two different roots x1=%d , x2=%d",x,y);
}
if(s == 0 && x == y) {
printf("Two same roots x=%d",-b/(2*a));
}
if(s < 0) {
printf("No real root");
}
return 0;
}
大神 問一下 我打的為什麼不行過@@?
#include
#include
int main() {
int a, b, c, x1, x2;
scanf("%d %d %d", &a, &b, &c);
double 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", x1, x2);
} else if (d == 0) {
x1 = (-b) / 2 * a;
printf("Two same roots x=%d", x1);
} else {
printf("No real root");
}
return 0;
}
2*a要用括號包起來