【蓝桥杯-练习系统】P1103

问题描述

编程实现两个复数的运算。

  要求:(1)定义一个结构体类型来描述复数。
  (2)复数之间的加法、减法、乘法和除法分别用不用的函数来实现。
  (3)必须使用结构体指针的方法把函数的计算结果返回。
  说明:用户输入:运算符号(+,-,*,/) a b c d.
  输出:a+bi,输出时不管a,b是小于0或等于0都按该格式输出,输出时a,b都保留两位。

样例输入

  - 2.5 3.6 1.5 4.9

样例输出

  1.00+-1.30i


代码

#include <stdio.h>
struct complex {
	double real;
	double image;
};

complex res;

complex *add(complex a, complex b)
{
	res.real = a.real + b.real;
	res.image = a.image + b.image;
	return &res;
}

complex *sub(complex a, complex b)
{
	res.real = a.real - b.real;
	res.image = a.image - b.image;
	return &res;
}

complex *mul(complex a, complex b)
{
	res.real = a.real * b.real - a.image * b.image;
	res.image = a.real * b.image + a.image *
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值