#include<stdio.h>
#include<stdlib.h>
typedef struct Complex
{
float real;
float image;
}Complex;
void CreatComplex(Complex& c,float a,float b);
void AddComplex(Complex& sum,Complex c1,Complex c2 );
void SubComplex(Complex& Sub,Complex c1,Complex c2 );
void MulComplex(Complex& Mul,Complex c1,Complex c2 );
void PrintComplex(Complex c);
void CreatComplex(Complex& c,float a,float b)
{
c.real = a;
c.image = b;
}
void AddComplex(Complex& sum,Complex c1,Complex c2)
{
sum.real = c1.real + c2.real ;
sum.image = c1.image + c2.image;
}
void SubComplex(Complex& Sub,Complex c1,Complex c2 )
{
Sub.real = c1.real -c2.real ;
Sub.image = c1.image - c2.image ;
}
void MulComplex(Complex& Mul,Complex c1,Complex c2 )
{
Mul.real = c1.real * c2.real - c1.image * c2.image ;
Mul.image = c1.real * c2.image + c1.image * c2.real ;
}
void ChuComplex(Complex& Chu,Complex c1,Complex c2)
{
Chu.real=(c1.real * c2.real - c1.image * c2.image)/(c2.real*c2.real-c1.image*c1.image);
Chu.image=(c1.real * c2.image + c1.image * c2.real)/(c2.real*c2.real-c1.image*c1.image);
}
void PrintComplex(Complex c)
{
if (c.image == 0.0)
printf("%5.2f\n",c.real );
else
{
if(c.real==0.0)
printf("%5.2fi\n",c.image);
else
printf("%5.2f+%5.2fi\n",c.real ,c.image );
}
}
void Printreal(Complex c)
{ printf("该复数的实部是:%5.2f\n",c.real);
}
void Printimage(Complex c)
{
printf("该复数的虚部是:%5.2f\n",c.image);
}
int main()
{
float a,b,c,d;
Complex c1,c2,Sum,Sub,Mul,Chu;
printf("请输入第一个复数的实部和虚部:");
scanf("%f %f",&a,&b);
printf("请输入第二个复数的实部和虚部:");
scanf("%f %f",&c,&d);
CreatComplex(c1,a,b);
PrintComplex(c1);
Printreal(c1);
Printimage(c1);
CreatComplex(c2,c,d);
PrintComplex(c2);
Printreal(c2);
Printimage(c2);
AddComplex(Sum,c1,c2);
PrintComplex(Sum);
SubComplex(Sub,c1,c2);
PrintComplex(Sub);
MulComplex(Mul,c1,c2);
PrintComplex(Mul);
ChuComplex( Chu, c1, c2);
PrintComplex(Chu);
return 0;
}
#include<stdlib.h>
typedef struct Complex
{
float real;
float image;
}Complex;
void CreatComplex(Complex& c,float a,float b);
void AddComplex(Complex& sum,Complex c1,Complex c2 );
void SubComplex(Complex& Sub,Complex c1,Complex c2 );
void MulComplex(Complex& Mul,Complex c1,Complex c2 );
void PrintComplex(Complex c);
void CreatComplex(Complex& c,float a,float b)
{
c.real = a;
c.image = b;
}
void AddComplex(Complex& sum,Complex c1,Complex c2)
{
sum.real = c1.real + c2.real ;
sum.image = c1.image + c2.image;
}
void SubComplex(Complex& Sub,Complex c1,Complex c2 )
{
Sub.real = c1.real -c2.real ;
Sub.image = c1.image - c2.image ;
}
void MulComplex(Complex& Mul,Complex c1,Complex c2 )
{
Mul.real = c1.real * c2.real - c1.image * c2.image ;
Mul.image = c1.real * c2.image + c1.image * c2.real ;
}
void ChuComplex(Complex& Chu,Complex c1,Complex c2)
{
Chu.real=(c1.real * c2.real - c1.image * c2.image)/(c2.real*c2.real-c1.image*c1.image);
Chu.image=(c1.real * c2.image + c1.image * c2.real)/(c2.real*c2.real-c1.image*c1.image);
}
void PrintComplex(Complex c)
{
if (c.image == 0.0)
printf("%5.2f\n",c.real );
else
{
if(c.real==0.0)
printf("%5.2fi\n",c.image);
else
printf("%5.2f+%5.2fi\n",c.real ,c.image );
}
}
void Printreal(Complex c)
{ printf("该复数的实部是:%5.2f\n",c.real);
}
void Printimage(Complex c)
{
printf("该复数的虚部是:%5.2f\n",c.image);
}
int main()
{
float a,b,c,d;
Complex c1,c2,Sum,Sub,Mul,Chu;
printf("请输入第一个复数的实部和虚部:");
scanf("%f %f",&a,&b);
printf("请输入第二个复数的实部和虚部:");
scanf("%f %f",&c,&d);
CreatComplex(c1,a,b);
PrintComplex(c1);
Printreal(c1);
Printimage(c1);
CreatComplex(c2,c,d);
PrintComplex(c2);
Printreal(c2);
Printimage(c2);
AddComplex(Sum,c1,c2);
PrintComplex(Sum);
SubComplex(Sub,c1,c2);
PrintComplex(Sub);
MulComplex(Mul,c1,c2);
PrintComplex(Mul);
ChuComplex( Chu, c1, c2);
PrintComplex(Chu);
return 0;
}