目录

2025-03-08-学习记录-CC-PTA-习题9-2-计算两个复数之积

2025-03-08 学习记录–C/C++-PTA 习题9-2 计算两个复数之积

合抱之木,生于毫末;九层之台,起于累土;千里之行,始于足下。💪🏻

一、题目描述 ⭐️

https://i-blog.csdnimg.cn/direct/e457229e8755442c886cec75aa91e8b2.png

https://i-blog.csdnimg.cn/direct/7c639a84c2ed4203a2586e0dc41cebff.png

二、代码(C语言)⭐️

#include <stdio.h>

struct complex{
    int real;
    int imag;
};

struct complex multiply(struct complex x, struct complex y);

int main()
{
    struct complex product, x, y;

    scanf("%d%d%d%d", &x.real, &x.imag, &y.real, &y.imag);
    product = multiply(x, y);
    printf("(%d+%di) * (%d+%di) = %d + %di\n", 
            x.real, x.imag, y.real, y.imag, product.real, product.imag);
    
    return 0;
}

/* 你的代码将被嵌在这里 */
struct complex multiply(struct complex x, struct complex y) {
    struct complex z;
    z.real = x.real * y.real - x.imag * y.imag; // 计算实部
    z.imag = x.real * y.imag + x.imag * y.real; // 计算虚部
    return z;
}

https://i-blog.csdnimg.cn/direct/01c0d42a67d14ac8a10a8f7a2a21ffa0.png

三、知识点 ⭐️

复数四则运算(加、减、乘、除),请查看 。

https://i-blog.csdnimg.cn/direct/efe0f7834b6b4ff48fe2415508d6c0f5.jpeg