#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 PrintComplex(Complex c)
{
if (c.image == 0.0)
printf("%5.2f",c.real );
else
{
if(c.real==0.0)
printf("%5.2fi",c.image);
else
printf("%5.2f+%5.2fi",c.real ,c.image );
}
}
评论0
最新资源