不是二次方程的工作根

时间:2018-11-19 19:25:22

标签: c equation

我什至无法从键盘上拿起bc。输入a值后它将停止,并始终给出结果,如0.0000。此代码有什么问题?

#include <iostream>
#include <math.h>

int main() {

    float a,b,c,d;
    float x1,x2;

    printf("enter a,b,c\n");
    scanf("%f %f %f", &a, &b, &c);

    d = b*b - 4*a*c;

    if (d<0) {
        printf ("no real roots");
    }
    else 
    {
        x1= (-b + sqrt (d)) / 2*a;
        x2= (-b - sqrt (d)) / 2*a;

        printf ("the roots are\n");
        printf ("x1=%f x2=%f",x1,x2);
    }

    return 0;
}

0 个答案:

没有答案