#include<stdio.h>//复数的加法和乘法 struct complex//定义一个复数结构体类型 {float real,imaj;};struct complex product (struct complex a, struct complex b)//这是定义了一个函数来求复数的乘法,至于加法没必要 {struct complex result;result.real=a.real*b.real-a.imaj*b.imaj;result.imaj=a.real*b.imaj+a.imaj*b.real;return result;}void main(){struct complex first,second,sum,prod;//定义4个变量 printf("please input the first complex num:
");scanf("%f%f",&first.real,&first.imaj);printf("please input the second complex num:
");scanf("%f%f",&second.real,&second.imaj);sum.real=first.real+second.real;sum.imaj=first.imaj+second.imaj;prod=product(first,second);printf("sum is :
");printf("%7.2f+%7.2f
",sum.real,sum.imaj);printf("product is :
");printf("%7.2f+%7.2f",prod.real,prod.imaj);}