#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