#include<stdio.h>
#include<math.h>
float x1,x2,disc,p,q;
int main()
{
void greater_than_zero(float,float);
void equal_to_zero(float,float);
void smaller_than_zero(float,float);
float a,b,c;
printf("\ninput a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
printf("equation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("root:\n");
if(disc>0)
{
greater_than_zero(a,b);
printf("x1=%f\t\tx2=%f\n",x1,x2);
}
else if(disc==0)
{
equal_to_zero(a,b);
printf("x1=%f\t\tx2=%f\n",x1,x2);
}
else
{
smaller_than_zero(a,b);
printf("x1=%f+%fi\tx2=%f-%fi\n",p,q,p,q);
}
system("pause");
}
void greater_than_zero(float a,float b)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}
void equal_to_zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}
void smaller_than_zero(float a,float b)
{
p=-b/(2*a);
q=sqrt(-disc)/(2*a);
}
1.传统上,C语言要求必须在一个代码块的开始处声明变量,在这之前不允许任何其他语句。现在C99遵循C++的惯例,允许把声明放在代码块中的任何位置。然而,在首次使用变量之前仍然必须先声明它。
2.操作系统和C库通常使用以一个或两个下划线开始的名字,因些你自己最好避免这种用法。
3.C语言的名字是区分大小写的。 ......