| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：20  回复次数：1
C++实验，实现复数的四则运算
//可直接调用库函数，试运行的时候能输入choice,但是正确进入switch...
//输入1后直接结束程序。

int main()
{
Complex z1,z2,z,sum,sub,mul,div,c;
float a,b;
char OPTR;
int choice;
printf("1.Achieve addition, subtraction, multiplication and division of complex numbers.\n");
printf("2.Separating the real part from the known complex number.\n");
printf("3.Separating the image part from the known complex number.\n");
printf("Please enter the functions you want to achieve:");
scanf("%d",&choice);
switch(choice)
{  case '1':
scanf("%f+%fi",&a,&b);
z1=CreatComplex(a,b);
scanf("%f+%fi",&a,&b);
z2=CreatComplex(a,b);
if(OPTR=='+')
else if(OPTR=='-')
{sub=Complex_Sub(z1,z2);PrintComplex(sub);}
else if(OPTR=='*')
{mul=Complex_Mul(z1,z2);PrintComplex(mul);}
else if(OPTR=='/')
{div=Complex_Div(z1,z2);PrintComplex(div);}
else
printf("The operator that you input is wrong!");
break;}
case '2':
scanf("%f+%fi",&a,&b);
z=CreatComplex(a,b);
printf("%f",GetReal(z));
break;}
case '3':break;
scanf("%f+%fi",&a,&b);
z=CreatComplex(a,b);
printf("%f",GetImage(z));
break;}
}
}

得分:20
scanf("%f%f",&a,&b);
• 2
• 1/1页
• 1