(最后是用TC3)利用结构体实现复数的加、减、乘、除和取模运算

来源:百度知道 编辑:UC知道 时间:2024/05/16 12:03:16
只能用C语言 不要用c++

定义复数的结构体

typedef struct{
double shibu;
double xubu;
}FuShu;

FunShu Add(FuShu a,FuShu b)
{
FuShu c;
c.shibu=a.shibu+b.shibu;
c.xubu=a.xubu+b.xubu;
reuturn c;
}

FunShu Sub(FuShu a,FuShu b)
{
FuShu c;
c.shibu=a.shibu-b.shibu;
c.xubu=a.xubu-b.xubu;
reuturn c;
}

FunShu Mul(FuShu a,FuShu b)
{
FuShu c;
c.shibu=a.shibu*b.shibu-a.xubu*b.xubu;
c.xubu=a.shibu*b.xubu+a.xubu*b.shibu;
reuturn c;
}

这个需要 #include "math.h"
FunShu Div(FuShu a,FuShu b) //高中数学都忘干净了
{
FuShu c;
double p,q,s,w;
p=a.shibu*b.shibu;
q=0-(a.xubu*b.xubu);
s=(a.shibu+a.xubu)*(b.shibu-b.xubu);
w=b.shibu*b.shibu+b.xubu*b.xubu;
if (w+1.0==1.0) //如果b的模为零
{ c.shibu=1.0e+35*a.shibu/fabs(a.shibu);
c.xubu=1.0e+35*a.xubu/fabs(a.xubu);
}
else