Top / Docs / 練習問題 / 解答例 / 二次方程式の解 / C

問題文

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

void f(double a, double b, double c) {
    double D, x1, x2;
    D = b*b - 4*a*c;
    if(D >= 0) {
        x1 = (fabs(b) + sqrt(D)) / (2. * a);
        x1 = b < 0 ? x1 : -x1;
        if(D > 0) {
            x2 = c / (a * x1);
            printf("%lf, %lf\n", x1, x2);
        } else {
            printf("%lf\n", x1);
        }
    }
}

int main(void) {
    f(0.0000000045, 10, 1);
    return 0;
}
📝 このページに誤りを見つけたら…  GitHubで報告(エンジニア向け)  ・  フォームで報告