mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
52 lines
686 B
Markdown
52 lines
686 B
Markdown
|
# 6-6 复数相乘运算
|
|||
|
|
|||
|
本题要求实现一个函数,可计算两个复数相乘的积。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
PLEX multi(PLEX a,PLEX b);
|
|||
|
```
|
|||
|
|
|||
|
其中 `a` 和 `b` 都是复数,返回值也为复数,值为a*b的值。
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include <stdio.h>
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
float re,im;
|
|||
|
}PLEX;
|
|||
|
|
|||
|
PLEX multi(PLEX a,PLEX b);
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
PLEX x,y,z;
|
|||
|
scanf("%f%f",&x.re,&x.im);
|
|||
|
scanf("%f%f",&y.re,&y.im);
|
|||
|
z=multi(x,y);
|
|||
|
if(z.im>=0)
|
|||
|
printf("%.2f+%.2fi",z.re,z.im);
|
|||
|
else
|
|||
|
printf("%.2f%.2fi",z.re,z.im);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* 请在这里填写答案 */
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例:
|
|||
|
|
|||
|
|
|||
|
```in
|
|||
|
1 2
|
|||
|
3 4
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例:
|
|||
|
|
|||
|
|
|||
|
```out
|
|||
|
-5.00+10.00i
|
|||
|
```
|