# include
# include /*此頭文件為調(diào)用 sqrt() 求平方根而用*/
int main(void)
{
int a;
int b;
int c;
double x1;
double x2;
double delta; //定義 delta = b*b = 4*a*c
/*請用戶輸入三個整數(shù) a b c, 并分別以空格鍵為間隔*/
printf("請分別輸入一元二次方程 a b c 的三個數(shù)值,請以空格為間隔:\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一元二次方程解
URL鏈接:
http://weahome.cn/article/gisecj.html