#6044: CE 為什麼呢??


mabinogi80503 (焚離)


#include <stdio.h>
#include <math.h>

int main() {
    double a = 0, b = 0, c = 0 ;
    double x1 = 0, x2 = 0 ;
    while( scanf( "%d%d%d", &a, &b, &c) != EOF ) {
        if ( ( b * b ) - 4 * a * c > 0 ) {
            x1 = ( -b + sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            x2 = ( -b - sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            printf( "Two different roots x1=%d , x2=%d\n", x1, x2 ) ;
        }
        else if ( ( b * b ) - 4 * a * c == 0 ) {
      x1 = ( -b ) / 2 / a ;
      printf( "Two same roots x=%d\n", x1 ) ;
        }
        else {
            printf( "No real root\n" ) ;
        }
    }
  return 0 ;
}

我放進去測試馬上CE

可是Dev C++ 中是正常的欸

#6045: Re:CE 為什麼呢??


sponge (qd)


#include
#include

int main() {
    double a = 0, b = 0, c = 0 ;
    double x1 = 0, x2 = 0 ;
    while( scanf( "%d%d%d", &a, &b, &c) != EOF ) {
        if ( ( b * b ) - 4 * a * c > 0 ) {
            x1 = ( -b + sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            x2 = ( -b - sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            printf( "Two different roots x1=%d , x2=%d\n", x1, x2 ) ;
        }
        else if ( ( b * b ) - 4 * a * c == 0 ) {
      x1 = ( -b ) / 2 / a ;
      printf( "Two same roots x=%d\n", x1 ) ;
        }
        else {
            printf( "No real root\n" ) ;
        }
    }
  return 0 ;
}

我放進去測試馬上CE

可是Dev C++ 中是正常的欸


你用 sqrt 難免產生誤差,

我是想辦法把等號2邊都平方,避免使用 sqrt

 

 

#6046: Re:CE 為什麼呢??


sponge (qd)


#include
#include

int main() {
    double a = 0, b = 0, c = 0 ;
    double x1 = 0, x2 = 0 ;
    while( scanf( "%d%d%d", &a, &b, &c) != EOF ) {
        if ( ( b * b ) - 4 * a * c > 0 ) {
            x1 = ( -b + sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            x2 = ( -b - sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            printf( "Two different roots x1=%d , x2=%d\n", x1, x2 ) ;
        }
        else if ( ( b * b ) - 4 * a * c == 0 ) {
      x1 = ( -b ) / 2 / a ;
      printf( "Two same roots x=%d\n", x1 ) ;
        }
        else {
            printf( "No real root\n" ) ;
        }
    }
  return 0 ;
}

我放進去測試馬上CE

可是Dev C++ 中是正常的欸


你用 sqrt 難免產生誤差,

我是想辦法把等號2邊都平方,避免使用 sqrt

 

 

喔 抱歉 我回錯了
#6047: Re:CE 為什麼呢??


sponge (qd)


#include
#include

int main() {
    double a = 0, b = 0, c = 0 ;
    double x1 = 0, x2 = 0 ;
    while( scanf( "%d%d%d", &a, &b, &c) != EOF ) {
        if ( ( b * b ) - 4 * a * c > 0 ) {
            x1 = ( -b + sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            x2 = ( -b - sqrt( ( b * b ) - 4 * a * c ) ) / 2 / a ;
            printf( "Two different roots x1=%d , x2=%d\n", x1, x2 ) ;
        }
        else if ( ( b * b ) - 4 * a * c == 0 ) {
      x1 = ( -b ) / 2 / a ;
      printf( "Two same roots x=%d\n", x1 ) ;
        }
        else {
            printf( "No real root\n" ) ;
        }
    }
  return 0 ;
}

我放進去測試馬上CE

可是Dev C++ 中是正常的欸