[quote][bo][un]luo123[/un] 在 2008-10-24 00:29 的发言:[/bo]
自己弄的
#include "stdio.h"
#include "math.h"
#include "conio.h"
int panduan(int a,int b,int c)
{
int m;
m=b*b-4*a*c;
return(m);
}
int main(void)
{int a,b,c,flag;
float x1,x2,ture,virture;
int swt;
printf("请依次输入二次方程的系数:\n");
scanf("%d,%d,%d",&a,&b,&c);
flag=panduan(a,b,c);
if(flag==0)
swt=0;
else if(flag>0)
swt=1;
else
swt=2;
switch(swt)
{
case 0: x1=-b/(2*a);printf("两个相等的实根为:x1=x2=%d\n",x1); break;
case 1: x1=(-b+sqrt(flag))/(2*a); x2=(-b-sqrt(flag))/(2*a); printf("两个不相等的实根为:x1=%6f,x2=%6f\n",x1,x2); break;
case 2: ture=-b/(2*a); virture=sqrt(-flag)/(2*a); printf("两个不相等的虚根:x1=%6f+%6fi,x2=%6f-%6fi\n ",ture,virture,ture,virture); break;
}
getch();
return 0;/*这一句不能少啊*/
}