栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

实验9-4 计算两个复数之积 (15 分)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实验9-4 计算两个复数之积 (15 分)

本题要求实现一个计算复数之积的简单函数。

函数接口定义:
struct complex multiply(struct complex x, struct complex y);

其中struct complex是复数结构体,其定义如下:

struct complex{
    int real;
    int imag;
};

裁判测试程序样例:
#include 

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 + %din", 
            x.real, x.imag, y.real, y.imag, product.real, product.imag);

    return 0;
}

输入样例:
3 4 5 6

结尾无空行

输出样例:
(3+4i) * (5+6i) = -9 + 38i

结尾无空行

struct complex multiply(struct complex x, struct complex y) //返回了一个结构multiply
{
    struct complex multiply;
    multiply.real = x.real * y.real - x.imag * y.imag;
    multiply.imag = x.imag * y.real + x.real * y.imag;
    return multiply;
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/511591.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号