c语言中求复数的和与积用以下结构描述复数信息struct complex{int real ,im;}; //分别表示复数的实部与虚部试写出两个通用函数,分别用来求两个复数的和与积.要求:①函数的返回值和形式参数用
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 02:37:09
c语言中求复数的和与积用以下结构描述复数信息struct complex{int real ,im;}; //分别表示复数的实部与虚部试写出两个通用函数,分别用来求两个复数的和与积.要求:①函数的返回值和形式参数用
c语言中求复数的和与积
用以下结构描述复数信息struct complex{int real ,im;}; //分别表示复数的实部与虚部试写出两个通用函数,分别用来求两个复数的和与积.要求:①函数的返回值和形式参数用结构体变量.其函数原型分别为struct complex cadd(struct complex creal,struct complex cim);struct complex cmult(struct complex creal,struct complex cim);②函数的返回值和形式参数用结构体指针变量.其函数原型分别为struct complex *cadd(struct complex *creal,struct complex *cim);struct complex *cmult(struct complex *creal,struct complex *cim);
请写全
c语言中求复数的和与积用以下结构描述复数信息struct complex{int real ,im;}; //分别表示复数的实部与虚部试写出两个通用函数,分别用来求两个复数的和与积.要求:①函数的返回值和形式参数用
1.
struct complex cadd(struct complex creal,struct complex cim)
{
complex c;
c.real=creal.real+cim.real;
c.im=creal.im+cim.im;
return c;
}
struct complex cmult(struct complex creal,struct complex cim)
{
complex c;
c.real=creal.real*cim.real-creal.im*cim.im;
c.im=creal.real*cim.im+creal.im*cim.real;
return c;
}
2.
struct complex *cadd(struct complex *creal,struct complex *cim)
{
complex c;
c.real=creal->real+cim->real;
c.im=creal->im+cim->im;
creal->real=c.real;
creal->im=c.im;
return creal;
}
struct complex *cmult(struct complex *creal,struct complex *cim)
{
complex c;
c.real=creal->real*cim->real-creal->im*cim->im;
c.im=creal->real*cim->im+creal->im*cim->real;
creal->real=c.real;
creal->im=c.im;
return creal;
}