c语言:输入俩个复数的实部与虚部,计算俩个复数之积,声明怎么声明?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 04:56:12
c语言:输入俩个复数的实部与虚部,计算俩个复数之积,声明怎么声明?
c语言:输入俩个复数的实部与虚部,计算俩个复数之积,声明怎么声明?
c语言:输入俩个复数的实部与虚部,计算俩个复数之积,声明怎么声明?
这个是一个列子,可以参考下
struct complex{
float rmz; //实部
float lmz;//虚部
};
//产生一个复数.
complex getAComplex(float a,float b){
complex Node=new complex();
Node.rmz=a;
Node.lmz=b;
return Node;}
//两个复数求和
complex addComplex(complex complex1,complex complex2)
{
complex Node=new complex();
Node.rmz=complex1.rmz+complex2.rmz;
Node.lmz=complex1.lmz+complex2.lmz;
return Node;
}
//求两个复数的差
complex subComplex(complex complex1,complex complex2)
{
complex Node=new complex();
Node.rmz=complex1.rmz-complex2.rmz;
Node.lmz=complex1.lmz-complex2.lmz;
return Node;
}
//求两个复数的积
complex productComplex(complex complex1,complex complex2)
{
complex Node=new complex();
Node.rmz=complex1.rmz*complex2.rmz-complex1.lmz*complex2.lmz;
Node.lmz=complex1.lmz*complex2.rmz+complex2.lmz*complex2.rmz;
return Node;
}
//求实部
float getComplexRmz(complex complex1)
{
return complex1.rmz;
}
//求虚部
float getComplexLmz(complex complex1)
{
return complex1.lmz;
}