#include<bits/stdc++.h>using namespace std;struct node{ double a,b;};node *add(node x,node y){ node *w=(node *)malloc(sizeof(node)); w->a=x.a+y.a; w->b=x.b+y.b; return w; }node *sub(node x,node y){ node *w=(node *)malloc(sizeof(node)); w->a=x.a-y.a; w->b=x.b-y.b; return w; }node *mul(node x,node y){ node *w=(node *)malloc(sizeof(node)); w->a=x.a*y.a-x.b*y.b; w->b=x.a*y.b+y.a*x.b; return w; }node *div(node x,node y){ node *w=(node *)malloc(sizeof(node)); w->a=(x.a*y.a+x.b*y.b)/(y.a*y.a+y.b*y.b); w->b=(x.b*y.a-x.a*y.b)/(y.a*y.a+y.b*y.b); return w; }int main(){ char c; struct node n,m; struct node *s; scanf("%c %lf %lf %lf %lf",&c,&n.a,&n.b,&m.a,&m.b); switch(c) { case '+': s=add(n,m); break; case '-': s=sub(n,m); break; case '*': s=mul(n,m); break; case '/': s=div(n,m); } PRintf("%.2lf+%.2lfi",s->a,s->b); return 0;}#include<stdio.h> int main() { char ch; double a,b,c,d; scanf("%c%lf%lf%lf%lf",&ch,&a,&b,&c,&d); if(ch=='+') { printf("%.2lf+%.2lfi",a+c,b+d); } if(ch=='-') { printf("%.2lf+%.2lfi",a-c,b-d); } if(ch=='*') { printf("%.2lf+%.2lfi",a*c-b*d,a*d+b*c); } if(ch=='/') { printf("%.2lf+%.2lfi",(a*c+b*d)/(c*c+d*d),(b*c-a*d)/(c*c+d*d)); } return 0; }
新闻热点
疑难解答