求一个用c语言编写的能解二元一次方程组的程序,希望不要是复制粘贴别处的

2024-11-05 01:15:31
推荐回答(1个)
回答(1):

/*一.关于自动解一元二次方程*/
#include
#include
#include  
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;
}