解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <iomanip>
using namespace std;
typedef struct{
double a;
double b;
}point; //别名
point add(point x,point y)
{
point sum;
sum.a=x.a+y.a;
sum.b=x.b+y.b;
return sum;
}
point jianhao(point x,point y)
{
point sum;
sum.a=x.a-y.a;
sum.b=x.b-y.b;
return sum;
}
point chenghao(point x,point y)
{
point sum;
sum.a=x.a*y.a-x.b*y.b;
sum.b=x.a*y.b+x.b*y.a;
return sum;
}
point chuhao(point x,point y)
{
point sum;
sum.a=(x.a*y.a+x.b*y.b)*1.0/(pow(y.a,2)+pow(y.b,2));
sum.b=(x.b*y.a-x.a*y.b)*1.0/(pow(y.a,2)+pow(y.b,2));
return sum;
}
int main(){
point x,y,result; //自定义变量
char fuhao;
double a,b,c,d;
cin>>fuhao>>a>>b>>c>>d;
x.a=a;
x.b=b;
y.a=c;
y.b=d;
double s;
if(fuhao=='+')
{
result=add(x,y);
}
else if(fuhao=='-')
result =jianhao(x,y);
else if(fuhao=='*')
result=chenghao(x,y);
else if(fuhao=='/')
result =chuhao(x,y);
cout<<fixed<<setprecision(2)<<result.a<<"+"<<result.b<<"i";
cout<<endl;
return 0;
}
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1555 |
C语言训练-大、小写问题 (C语言代码)浏览:792 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:590 |
1025题解浏览:796 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:537 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:569 |
printf基础练习2 (C语言代码)浏览:547 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:755 |
剪刀石头布 (C语言代码)浏览:1519 |
简单的a+b (C语言代码)浏览:683 |