我也輸入了include<math.h>
,但它仍然不起作用。人們正在說要進入 - 我但是我不知道這個位置 - 我該如何解決這個問題。C程序sqrt不工作
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
float a=0, b=0, c=0, root1=0, root2=0;
printf("Enter the value of a,b and c to determine the roots\n");
scanf("%f%f%f",&a,&b,&c);
root1=(-b+sqrt(b*b-4*a*c))/(2*a);
root1=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("The first roots of the quadratic equation are\nFirst root=%.1f\nSecond root=%.1f",root1,root2);
return 0;
}
如果您告訴我們它「不起作用」,這將有所幫助。你有錯誤嗎?什麼錯誤? –
您應該將第二個根分配給'root2',而不是覆蓋'root1'。你應該檢查輸入是否成功。你應該檢查一下'b * b'是否不小於'4 * a * c'。 –
你可以嘗試像這樣編譯你的程序「gcc prog.c -o prog -lm」 –