主题:帮忙看看我的复数运行为什么结果错的
#include <stdio.h>
#include <stdlib.h>
typedef struct Complex{
float sb;
float xb;
}Complex;
Complex InitComplex(float sb,float xb);
Complex AddCom(Complex nc1,Complex nc2);
Complex SubCom(Complex nc1,Complex nc2);
Complex MulCom(Complex nc1,Complex nc2);
main()
{
Complex c1,c2,c3;
float sb1,xb1,sb2,xb2;
int choice;
printf("Intput 1 it will Addtion\n Intput 2 it will subtraction\n Intput 3 it will multiplication\n");
printf("Intput 4 it will exit\n\n");
printf("input the sb and the xb of Complex1:");
scanf("%f%f%f%f",&sb1,&xb1,&sb2,&xb2);
c1=InitComplex(sb1,xb1);
c2=InitComplex(sb2,xb2);
while(1){
printf("input you choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c3=AddCom(c1,c2);
printf("the addition is %f:",c3);
break;
case 2:
c3=SubCom(c1,c2);
printf("the subtration is %f:,c3");
break;
case 3:
c3=MulCom(c1,c2);
printf("the multiplication is %f:,c3");
break;
case 4:
break;
}
if(choice==4)
break;
}
}
Complex InitComplex(float sb,float xb)
{
Complex C;
C.sb=sb;
C.xb=xb;
return C;
}
Complex AddCom(Complex c1,Complex c2)
{
Complex AddComplex;
AddComplex.sb=c1.sb+c2.sb;
AddComplex.xb=c1.xb+c2.xb;
return AddComplex;
}
Complex SubCom(Complex c1,Complex c2)
{
Complex SubComplex;
SubComplex.sb=c1.sb-c2.sb;
SubComplex.xb=c1.xb-c2.xb;
return SubComplex;
}
Complex MulCom(Complex c1,Complex c2)
{
Complex MulComplex;
float a,b,c,d;
a=c1.sb;
b=c1.xb;
c=c2.sb;
d=c2.xb;
MulComplex.sb=a*c-b*d;
MulComplex.xb=b*c+a*d;
return MulComplex;
}
能运行,但是结果不对……麻烦大家帮我看看
#include <stdlib.h>
typedef struct Complex{
float sb;
float xb;
}Complex;
Complex InitComplex(float sb,float xb);
Complex AddCom(Complex nc1,Complex nc2);
Complex SubCom(Complex nc1,Complex nc2);
Complex MulCom(Complex nc1,Complex nc2);
main()
{
Complex c1,c2,c3;
float sb1,xb1,sb2,xb2;
int choice;
printf("Intput 1 it will Addtion\n Intput 2 it will subtraction\n Intput 3 it will multiplication\n");
printf("Intput 4 it will exit\n\n");
printf("input the sb and the xb of Complex1:");
scanf("%f%f%f%f",&sb1,&xb1,&sb2,&xb2);
c1=InitComplex(sb1,xb1);
c2=InitComplex(sb2,xb2);
while(1){
printf("input you choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c3=AddCom(c1,c2);
printf("the addition is %f:",c3);
break;
case 2:
c3=SubCom(c1,c2);
printf("the subtration is %f:,c3");
break;
case 3:
c3=MulCom(c1,c2);
printf("the multiplication is %f:,c3");
break;
case 4:
break;
}
if(choice==4)
break;
}
}
Complex InitComplex(float sb,float xb)
{
Complex C;
C.sb=sb;
C.xb=xb;
return C;
}
Complex AddCom(Complex c1,Complex c2)
{
Complex AddComplex;
AddComplex.sb=c1.sb+c2.sb;
AddComplex.xb=c1.xb+c2.xb;
return AddComplex;
}
Complex SubCom(Complex c1,Complex c2)
{
Complex SubComplex;
SubComplex.sb=c1.sb-c2.sb;
SubComplex.xb=c1.xb-c2.xb;
return SubComplex;
}
Complex MulCom(Complex c1,Complex c2)
{
Complex MulComplex;
float a,b,c,d;
a=c1.sb;
b=c1.xb;
c=c2.sb;
d=c2.xb;
MulComplex.sb=a*c-b*d;
MulComplex.xb=b*c+a*d;
return MulComplex;
}
能运行,但是结果不对……麻烦大家帮我看看