5个回答
展开全部
#include "stdio.h"
#include "math.h"
/*求一元二次方程ax*x+bx+c=0的解*/
main()
{
float a,b,c,x1,x2,d;
printf("请输入a:");
scanf("%f",&a);
printf("请输入b:");
scanf("%f",&b);
printf("请输入c:");
scanf("%f",&c);
d=b*b-4*a*c;
if(d < 0)
printf("方程没有实数解。\n");
if (d==0)
{
x1=(-b)/(2*a);
printf("x1=%f\n",x1);
}
if (d>0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);}
}
请输入a:12
请输入b:34
请输入c:4
x1=-0.122985,x2=-2.710348
Press any key to continue
推荐于2017-11-26
展开全部
上课时编的,测试过可用。/* Note:Your choice is C IDE */
#include "stdio.h"
#include <math.h>
void main()
{
int a,b,c,d,e;
e=1;
while (e)
{printf("求一个一元二次方程的根");
printf("ax^2+bx+c=0\n");
printf("请输入a=");
scanf("%d",&a);
if(a==0)
{
break;
}printf("请输入b=");
scanf("%d",&b);
printf("请输入c=");
scanf("%d",&c);
d=b*b-4*a*c;
if(d<0)
{
printf("无实数解\n");
}
else if(d==0)
{
printf("只有一个根为:%f\n",-b/(2.0*a));
}
else
{printf("有两个根为:%f%f\n",(-b+sqrt(e))/(2.0*a),(-b-sqrt(e))/(2.0*a));
}}
}
#include "stdio.h"
#include <math.h>
void main()
{
int a,b,c,d,e;
e=1;
while (e)
{printf("求一个一元二次方程的根");
printf("ax^2+bx+c=0\n");
printf("请输入a=");
scanf("%d",&a);
if(a==0)
{
break;
}printf("请输入b=");
scanf("%d",&b);
printf("请输入c=");
scanf("%d",&c);
d=b*b-4*a*c;
if(d<0)
{
printf("无实数解\n");
}
else if(d==0)
{
printf("只有一个根为:%f\n",-b/(2.0*a));
}
else
{printf("有两个根为:%f%f\n",(-b+sqrt(e))/(2.0*a),(-b-sqrt(e))/(2.0*a));
}}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <math.h>
double x1,x2,p;
float file1(float a,float b)
{
x1=(-b+sqrt(p))/2*a;
x2=(-b-sqrt(p))/2*a;
return 0;
}
float file2(float a,float b)
{
x1=x2=(-b+sqrt(p))/2*a;
return 0;
}
void main()
{
float a,b,c;
printf("请依次输入方程的三个系数:\n");
scanf("%f%f%f",&a,&b,&c);
p=b*b-4*a*c;
printf("方程是:%.1f*x*x + %.1f*x + %.1f = 0\n",a,b,c);
if(p>0)
{
file1(a,b);
printf("X1=%f\tX2=%f\n",x1,x2);
}
else if(p==0)
{
file2(a,b);
printf("X1=%f\tX2=%f\n",x1,x2);
}
else printf("方程无解");
}
#include <math.h>
double x1,x2,p;
float file1(float a,float b)
{
x1=(-b+sqrt(p))/2*a;
x2=(-b-sqrt(p))/2*a;
return 0;
}
float file2(float a,float b)
{
x1=x2=(-b+sqrt(p))/2*a;
return 0;
}
void main()
{
float a,b,c;
printf("请依次输入方程的三个系数:\n");
scanf("%f%f%f",&a,&b,&c);
p=b*b-4*a*c;
printf("方程是:%.1f*x*x + %.1f*x + %.1f = 0\n",a,b,c);
if(p>0)
{
file1(a,b);
printf("X1=%f\tX2=%f\n",x1,x2);
}
else if(p==0)
{
file2(a,b);
printf("X1=%f\tX2=%f\n",x1,x2);
}
else printf("方程无解");
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-01-09
展开全部
#include "stdio.h"
#include "conio.h"
#include "math.h"int fun(double a,double b,double c,double* result,int* resCount)
{
double p=0;
p=b*b-4*a*c;
if(p>0)
{
result[0]=(-b+sqrt(p))/(2*a);
result[1]=(-b-sqrt(p))/(2*a);
*resCount=2;
return 1;
}
else if(p==0)
{
result[0]=result[1]=-b/(2*a);
*resCount=1;
return 1;
}
else
return 0;
}void main()
{
double a[5]={0};
int iResCount=0;
printf("please Enter the a, b ,c values:");
scanf("%lf%lf%lf",a,a+1,a+2);
if(fun(a[0],a[1],a[2],a+3,&iResCount))
{
if(iResCount==2)
printf("Quadratic equation's Solution set is: %.4lf , %.4lf\n",a[3],a[4]);
else
printf("Quadratic equation's Solution set is: %lf \n",a[3]);
}
else
{
printf("Quadratic equation has no Solution set\n");
}
getchar();
getchar();
}
#include "conio.h"
#include "math.h"int fun(double a,double b,double c,double* result,int* resCount)
{
double p=0;
p=b*b-4*a*c;
if(p>0)
{
result[0]=(-b+sqrt(p))/(2*a);
result[1]=(-b-sqrt(p))/(2*a);
*resCount=2;
return 1;
}
else if(p==0)
{
result[0]=result[1]=-b/(2*a);
*resCount=1;
return 1;
}
else
return 0;
}void main()
{
double a[5]={0};
int iResCount=0;
printf("please Enter the a, b ,c values:");
scanf("%lf%lf%lf",a,a+1,a+2);
if(fun(a[0],a[1],a[2],a+3,&iResCount))
{
if(iResCount==2)
printf("Quadratic equation's Solution set is: %.4lf , %.4lf\n",a[3],a[4]);
else
printf("Quadratic equation's Solution set is: %lf \n",a[3]);
}
else
{
printf("Quadratic equation has no Solution set\n");
}
getchar();
getchar();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-01-09
展开全部
int a,x,b,c;printf("请输入整数A,X,B,C的值");sanf("%d%d%d%d",&a,&x,&b,&c);a*x*x+b*x+c=0;printf("x的值为%d",&x); (因为没有经过运行,不知道是否有些问题,但大体上这样就可以了)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询