#25763: C language 簡易寫法


22207807 (會打Code的貓)

School : 逢甲大學
ID : 156777
IP address : [51.79.156.19]
Last Login :
2021-09-07 13:32:07
a006. 一元二次方程式 | From: [42.72.17.218] | Post Date : 2021-06-21 13:24

#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;

}

 
#27113: Re:C language 簡易寫法


k689022123 (新手村出發)

School : 淡江大學
ID : 165129
IP address : [61.223.151.58]
Last Login :
2021-09-15 19:58:21
a006. 一元二次方程式 | From: [61.223.151.58] | Post Date : 2021-09-13 15:51

#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;

}

 
#27117: Re:C language 簡易寫法


cges30901 (cges30901)

School : No School
ID : 30877
IP address : [27.52.228.184]
Last Login :
2021-09-21 19:34:53
a006. 一元二次方程式 | From: [27.52.102.84] | Post Date : 2021-09-13 18:22

#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要用括號包起來

 
ZeroJudge Forum