
怎么把他这个不同的结果写出来啊,而且这个虚数用什么数据类型啊
#include "stdio.h"
#include<math.h>
#include<stdlib.h>
typedef struct complex
{
double _Val[2]; //real、img
}complex;
complex* getResult(double a,double b,double c,complex*res){
double delta=b*b-4*a*c;
if(delta>=0){
res[0]._Val[0] = (-b+sqrt(delta))/(2*a);
res[0]._Val[1] = 0;
res[1]._Val[0] = (-b-sqrt(delta))/(2*a);
res[1]._Val[1] = 0;
}else{
double absDelta = -delta;
double tmp = sqrt(absDelta)/(2*a);
res[0]._Val[0] = -b/(2*a);
res[0]._Val[1] = tmp;
res[1]._Val[1] = -tmp;
res[1]._Val[0] = -b/(2*a);
}
return res;
}
int main(){
double a,b,c;
complex res[2];
while(scanf("%lf,%lf,%lf",&a,&b,&c)!=EOF){
if(a==0){
printf("The equation is not a quadratic\n");
continue;
}
getResult(a,b,c,res);
if(res[0]._Val[1]!=0){//复数
printf("The quation has complex real roots:\n");
printf("%.4lf+%.4lfi\n",res[0]._Val[0],res[0]._Val[1]);
printf("%.4lf%.4lfi\n",res[1]._Val[0],res[1]._Val[1]);
}else if(res[0]._Val[0]!=res[1]._Val[0]){
printf("The quation has distinct real roots:%.4lf and %.4lf\n",res[0]._Val[0],res[1]._Val[0]);
}else{
printf("The quation has two equal real roots:%.4lf\n",res[0]._Val[0]);
}
}
system("pause");
}