#36737: 已經80%了,但還是不懂問題出在哪,求解


aa0979036765@gmail.com (瘋狗)


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

#36743: Re: 已經80%了,但還是不懂問題出在哪,求解


samlin961112@gmail.com (林哲甫)


#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