欢迎光临散文网 会员登陆 & 注册

1

2023-03-03 17:33 作者:-_-Monet-_-  | 我要投稿

#include<stdio.h>

typedef struct ComplexType

{

float realPart,imagePart;

} ComplexType;

ComplexType add(ComplexType z1, ComplexType z2);

ComplexType sub(ComplexType z1, ComplexType z2);

ComplexType multiply(ComplexType z1, ComplexType z2);

int main()

{

ComplexType a,b,c1,c2,c3;

scanf("%f %f",&a.realPart,&a.imagePart);

scanf("%f %f",&b.realPart,&b.imagePart);

c1=add(a,b);

printf("%f+%fi",c1.realPart,c1.imagePart);

c2=sub(a,b);

printf("%f+%fi",c2.realPart,c2.imagePart);

c3=multiply(a,b);

printf("%f+%fi",c3.realPart,c3.imagePart);

return 0;

}

ComplexType add(ComplexType z1, ComplexType z2){

ComplexType temp;

temp.realPart=z1.realPart+z2.realPart;

temp.imagePart=z1.imagePart+z2.imagePart;

return temp;

}

ComplexType sub(ComplexType z1, ComplexType z2){

ComplexType temp;

temp.realPart=z1.realPart-z2.realPart;

temp.imagePart=z1.imagePart-z2.imagePart;

return temp;

}

ComplexType multiply(ComplexType z1, ComplexType z2){

ComplexType temp;

temp.realPart=z1.realPart*z2.realPart;

temp.imagePart=z1.imagePart*z2.imagePart;

return temp;

}


1的评论 (共 条)

分享到微博请遵守国家法律