用C语言编写程序,用结构体的方法进行两个复数的相减

2024-11-08 07:48:09
推荐回答(3个)
回答1:

/*

c = 1+i2

Press any key to continue

*/

#include 
struct Complex {
double m_r;
double m_i;
};
void main() {
struct Complex c1 = {1.2,2.3},c2 = {0.2,0.3};
struct Complex c;
c.m_r = c1.m_r - c2.m_r;
c.m_i = c1.m_i - c2.m_i;
printf("c = %g+i%g\n",c.m_r,c.m_i);
}

回答2:

#include 
struct Complex
{
    double m_r;
    double m_i;
};
void main()
{
    struct Complex c1={1.2,2.3},c2={0.2,0.3};
    struct Complex c;
    c.m_r=c1.m_r+c2.m_r;
    c.m_i=c1.m_i+c2.m_i;
    printf("c=%g+i%g\n",c.m_r,c.m_i);
}

回答3:

填写如下

c.m_r = c1.m_r - c2.m_r;
c.m_i = c1.m_i - c2.m_i;

得到的答案是c = 1+i2