用c语言语言求求方程ax^2+bx+c=0的实数根,abc由键盘输入,a不等于0且b^2—4a
展开全部
/*一.关于自动解一元二次方程*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double a,b,c,del,k;
s:
printf ("a=");scanf ("%lf",&a);
printf ("b=");scanf ("%lf",&b);
printf ("c=");scanf ("%lf",&c);
del=pow (b,2)-4*a*c;
if (a==0) if (b==0&&c==0) printf ("If you want,it can be anything~");
else if (b==0&&c!=0) {printf ("Get out,don't ask me!\n");exit (0);}
else printf ("%.0lfX+%.0lf=0\nX=%lf",b,c,-c/b);//a为0时为一元一次方程
else if (0==del) printf ("有唯一解:%lfX^2+%lfX+%lf=0\nX=%lf",a,b,c,-b/(2*a));//del等于0
else if (0>del) printf ("无实数解!");
else printf ("%lfX^2+%lfX+%lf=0\nX1=%lf\nX2=%lf",a,b,c,(-b+sqrt(del))/2*a,(-b-sqrt(del))/2*a);
printf ("\ncontinue?");
scanf ("%d",&k);if (k==1) goto s;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double a,b,c,del,k;
s:
printf ("a=");scanf ("%lf",&a);
printf ("b=");scanf ("%lf",&b);
printf ("c=");scanf ("%lf",&c);
del=pow (b,2)-4*a*c;
if (a==0) if (b==0&&c==0) printf ("If you want,it can be anything~");
else if (b==0&&c!=0) {printf ("Get out,don't ask me!\n");exit (0);}
else printf ("%.0lfX+%.0lf=0\nX=%lf",b,c,-c/b);//a为0时为一元一次方程
else if (0==del) printf ("有唯一解:%lfX^2+%lfX+%lf=0\nX=%lf",a,b,c,-b/(2*a));//del等于0
else if (0>del) printf ("无实数解!");
else printf ("%lfX^2+%lfX+%lf=0\nX1=%lf\nX2=%lf",a,b,c,(-b+sqrt(del))/2*a,(-b-sqrt(del))/2*a);
printf ("\ncontinue?");
scanf ("%d",&k);if (k==1) goto s;
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询