#include <iostream>
#include <iomanip>
using namespace std;
struct complex
{ double re,im;
};
int main()
{ complex a,b,c; char oper;
cout << "输入复数a的实部和虚部: ";
cin >> a.re >> a.im;
cout << "输入复数b的实部和虚部:";
cin >> b.re >> b.im;
cout << "输入运算符: ";
cin >> oper;
switch ( oper )
{ case '+': c.re=a.re+b.re; c.im=a.im+b.im; break;
case '-': c.re=a.re-b.re; c.im=a.im-b.im; break;
case '*': c.re=a.re*b.re-a.im*b.im;
c.im=a.im*b.re+a.re*b.im; break;
case '/': c.re=(a.re*b.re+a.im*b.im)/(b.re*b.re+b.im*b.im);
c.im=(a.im*b.re-a.re*b.im)/(b.re*b.re+b.im*b.im);
break;
default: cout << "input error!" << endl;
return 0;
}
cout << "c=" << c.re;
cout << setiosflags( ios::showpos );
cout << c.im << "i" << endl;
return 0;
}
风筝飞的很远
相关分类