代码:
#include <stdio.h>
#include <math.h>
float x1,x2;
int main(){
float calculate1(int a,int b,int c);
float calculate2(int a,int b,int c);
float calculate3(int a,int b,int c);
float a,b,c,result;
printf(“请输入a的值\n”);
scanf("%f",&a);
printf(“请输入b的值\n”);
scanf("%f",&b);
printf(“请输入c的值\n”);
scanf("%f",&c);
result=sqrt(bb-4ac);
if(result==0)
calculate1(a,b,c);
else if(result>0)
calculate2(a,b,c);
else calculate3(a,b,c);
return 0;
}
float calculate1(int a,int b,int c){
x1=x2=(-b)/(2a);
printf(“方程%dxx+%dx+%d=0的根为:\n",a,b,c);
printf(“x1=%f,x2=%f\n”,x1,x2);
}
float calculate2(int a,int b,int c){
x1=(-b+sqrt(bb-4ac))/(2a);
x2=(-b-sqrt(bb-4ac))/(2a);
printf("方程%dxx+%dx+%d=0的根为:\n”,a,b,c);
printf(“x1=%f,x2=%f\n”,x1,x2);
}
float calculate3(int a,int b,int c){
float m,n;
m=-b/(2a);
n=sqrt(-(bb-4ac))/(2a);
printf("方程%dxx+%dx+%d=0的根为:\n",a,b,c);
printf(“x1=%f+%fi,x2=%f-%fi\n”,m,n,m,n);
}
运行结果: