编程求复数a,b,的加减乘除运算???
不够好
不要见笑
#include<stdio.h>
#include<math.h>
main()
{
float re1,im1,re2,im2;
float sumr,sumi,difr,difi,pror,proi,quor,quoi,p;
printf("input the first number:\n");
printf("real:");
scanf("%f",&re1);
printf("imaginary:");
scanf("%f",&im1);
printf("input the second number:\n");
printf("real:");
scanf("%f",&re2);
printf("imaginary:");
scanf("%f",&im2);
sumr=re1+re2;
sumi=im1+im2;
if(sumi<0)
printf("%f%fi\n",sumr,sumi);
else
printf("%f+%fi\n",sumr,sumi); /*addition*/
difr=re1-re2;
difi=im1-im2;
if(difi<0)
printf("%f%fi\n",difr,difi);
else
printf("%f+%fi\n",difr,difi); /*difference*/
pror=re1*re2-im1*im2;
proi=re1*im2+im1*re2;
if(proi<0)
printf("%f%fi\n",pror,proi);
else
printf("%f+%fi\n",pror,proi); /*product*/
p=pow(re2,2)+pow(im2,2);
quor=(re1*re2+im1*im2)/p;
quoi=(re2*im1-im2*re1)/p;
if(quoi<0)
printf("%f%fi\n",quor,quoi);
else
printf("%f+%fi\n",quor,quoi); /*quotient*/
getch();
}