#include <stdio.h>
#include <math.h>
int main(void)
{
double a, b, c, root1, root2;
printf("Input the coefficient a => ");
scanf("%lf", &a);
printf("Input the coefficient b => ");
scanf("%lf", &b);
printf("Input the coefficient c => ");
scanf("%lf", &c);
/* Compute the roots. */
root1 = (- b + sqrt(b*b-4*a*c))/(2*a);
root2 = (- b - sqrt(b*b-4*a*c))/(2*a);
printf("The first root is %8.3f\n", root1);
printf("The second root is %8.3f\n", root2);
return 0;
}
然而,我的輸出是代碼塊不打印特定格式
Input the coefficient a => 232
Input the coefficient b => 23
Input the coefficient c => 2
The first root is nan
The second root is nan
我只是一個初學者,是格式錯誤? 使用代碼塊,在C.
寫
負的平方根數字是'nan'。 – tkausl
你期望輸出什麼? – mch
我投票結束這個問題作爲題外話題,因爲它是一個數學問題,而不是編程問題。 – Lundin