问题描述
编程实现两个复数的运算。
(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 *