#25763: C language 簡易寫法


22207807 (會打Code的貓)


#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 (新手村出發)


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


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