设计一个复数类.从键盘输入2个复数,完成复数的加减运算,然后输出运算结果.struct complex{\x05double real;\x05double imaginary;};struct complex input(void){}struct complex plus(struct complex a,struct complex b){}struct comp

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 09:16:28
设计一个复数类.从键盘输入2个复数,完成复数的加减运算,然后输出运算结果.struct complex{\x05double real;\x05double imaginary;};struct complex input(void){}struct complex plus(struct complex a,struct complex b){}struct comp
xU]@+CEIi4%.$$R >UQba3MSɤI&u7TBs{L:ǛrX]>]~]Jqݩ.f,GB3rTJwA[2.DDG`DCWHd<{" 6X\n,DPV5m#I=ER`n3uD7I|aGER&6_mU2|`G8@=_!I)CrCn~^~~[motrd6iI_UD!vE NXc &7oc  xgV KcЩ2D!&Q =zn],h1} G/L6koej$A?H.aۢZ

设计一个复数类.从键盘输入2个复数,完成复数的加减运算,然后输出运算结果.struct complex{\x05double real;\x05double imaginary;};struct complex input(void){}struct complex plus(struct complex a,struct complex b){}struct comp
设计一个复数类.从键盘输入2个复数,完成复数的加减运算,然后输出运算结果.
struct complex
{
\x05double real;
\x05double imaginary;
};
struct complex input(void)
{
}
struct complex plus(struct complex a,struct complex b)
{
}
struct complex minus(struct complex a,struct complex b)
{
}
void output(struct complex a)
{
}
int main()
{
}

设计一个复数类.从键盘输入2个复数,完成复数的加减运算,然后输出运算结果.struct complex{\x05double real;\x05double imaginary;};struct complex input(void){}struct complex plus(struct complex a,struct complex b){}struct comp
#include
struct complex
{
double real;
double imaginary;
};
struct complex input(void)
{
struct complex num;
printf("input complex number (eg.2.0+1.1i):");
scanf("%lf+%lfi",&num.real,&num.imaginary);
return num;
}
struct complex plus(struct complex a,struct complex b)
{
struct complex num;
num.real = a.real + b.real;
num.imaginary = a.imaginary + b.imaginary;
return num;
}
struct complex minus(struct complex a,struct complex b)
{
struct complex num;
num.real = a.real - b.real;
num.imaginary = a.imaginary - b.imaginary;
return num;
}
void output(struct complex a)
{
printf("%lf + %lfi\n",a.real,a.imaginary);
}
int main()
{
struct complex n1,n2,sum,dif;
n1 = input();
printf("you inputed ");
output(n1);
n2 = input();
printf("you inputed ");
output(n2);
sum = plus(n1,n2);
printf("sum is ");
output(sum);
dif = minus(n1,n2);
printf("dif is ");
output(dif);
}
/tmp/c2> xx19
input complex number (eg.2.0+1.1i):2.0+1.1i
you inputed 2.000000 + 1.100000i
input complex number (eg.2.0+1.1i):42.0+3.2i
you inputed 42.000000 + 3.200000i
sum is 44.000000 + 4.300000i
dif is -40.000000 + -2.100000i