网站建设资讯

NEWS

网站建设资讯

C一元二次方程解

# include 
# include     /*此头文件为调用 sqrt() 求平方根而用*/

int main(void)
{
    int a;
    int b;
    int c;
    double x1;
    double x2;
    double delta;    //定义 delta = b*b = 4*a*c

        /*请用户输入三个整数 a b c, 并分别以空格键为间隔*/
    printf("请分别输入一元二次方程 a b c 的三个数值,请以空格为间隔:\n");
    scanf("%d %d %d", &a, &b, &c);

    delta = b*b - 4*a*c;
    if (delta > 0)
    {
        x1 = (-b + sqrt(delta)) / (2*a);
        x2 = (-b - sqrt(delta)) / (2*a);
        printf("该一元二次方程有两个解: x1 = %lf, x2 = %lf\n", x1, x2);
    }
    else if (delta == 0)
    {
        x1 = (-b) / (2*a);
        x2 = x1;
        printf("该一元二次方程有一个解: x1 = x2 = %lf\n", x1);
    }
    else
    {
        printf("无解\n");
    }

    return 0;
}

网站题目:C一元二次方程解
当前链接:http://cdweb.net/article/gisecj.html