热心网友
回答时间:2024-04-18 05:51
//===
#include <stdio.h>
#include <math.h>
float x1,x2;
//--
void greater(float a,float b,float disc) //disc大于零时
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("有两个不等实根:x1=%5.2f,x2=%5.2f\n",x1,x2);
}
//--
void equal(float a,float b,float disc) //disc等于零时
{
x1=(-b)/(2*a);
printf("有两个相等实根:x1=x2=%5.2f\n",x1);
}
//--
void smaller(float a,float b,float disc) //disc小于零时
{
x1=(-b)/(2*a);
x2=sqrt(-disc)/(2*a);
printf("有两个虚根:x1=%5.2f+%5.2fi,x2=%5.2f-%5.2fi\n",x1,x2,x1,x2);
}
//--
void main()
{
float a,b,c,disc;
printf("输入方程的系数:");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;
if(disc>0)
greater(a,b,disc);
else if(disc==0)
equal(a,b,disc);
else
smaller(a,b,disc);
}
//===
收起
热心网友
回答时间:2024-04-18 05:55
vc6.0下可以编译通过,你试试:
#include <stdio.h>
#include <math.h>
main()
{
int i=0;
float coeff[3],sum,temp;
printf("Ax*x+Bx+C=sum\n");
do{
printf("Input the %c value: ",i+65);
scanf("%f",&coeff[i]);
}while(++i<3);
printf("Input the sum value: ");scanf("%f",&sum);
printf("Ax*x+Bx+C=sum the answer is:\n");
temp=pow(coeff[1],2)-4*coeff[0]*coeff[2];
if(temp<0)
printf("The valueOen=valueTwo=NULL\n");
else
printf("The value is:\n vla_one=%.2f \n val_two=%.2f\n",(-coeff[1]-sqrt(temp))/2*coeff[0],(-coeff[1]+sqrt(temp))/2*coeff[0]);
}
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。
收起