计算二次方程的根

计算二次方程ax ^ 2 + bx + c = 0的根。

由以下公式给出:

(-b + square_root(b2 - 4ac))/2a        和      (-b - square_root(b2 - 4ac))/2a

参考以下代码

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

int main(){
    double a, b, c, d, result1, result2;
    char ch;

    printf(Enter the values of a, b and c : );
    scanf(%lf %lf %lf, &a, &b, &c);

    d = b * b - 4 * a * c;
    if (d == 0)
    {
        result1 = ( - b) / (2 * a);
        result2 = result1;
        printf(Roots are real & equal\n);
        printf(Root1 = %f, Root2 = %f\n, result1, result2);
    }
    else if (d > 0)
    {
        result1 =  - (b + sqrt(d)) / (2 * a);
        result2 =  - (b - sqrt(d)) / (2 * a);
        printf(Roots are real & distinct\n);
        printf(Root1 = %f, Root2 = %f\n, result1, result2);
    }
    else
    {
        printf(Roots are imaginary\n);
    }

    return 0;
}

相关文章

for遍历数组
。。。
声明一个计数循环
咕咕咕
#include <stdio.h> int main (void) { printf (&quo...