/*第一题*/
#include <stdio.h>
#include <conio.h>
typedef struct
/*自定义一个复数结构体*/
{
float real;
/*复数的实部*/
float image;
/*复数的虚部*/
}dataType;
/*声明复数相乘函数,传入两个复数,返回一个复数*/ dataType complexMult(dataType,dataType);
void main(void)
{
/*定义三个复数变量*/
dataType complex1,complex2,complex3;
/*初始化二个复数变量*/
complex1.real=3, complex1.image=4;
complex2.real=5, complex2.image=6;
/*函数调用*/ complex3=complexMult(complex1,complex2);
/*清屏*/
clrscr();
/*打印结果*/ printf("result:\n\t\(%.0f,%.0fi\)",complex3.real,complex3.image);
/*暂停*/
getch();
}
/*复数相乘函数的定义*/
dataType complexMult(dataType complex1,dataType complex2)
{
dataType complex3;
/*复数相乘的实部:实部与实部相乘 减去 虚部与虚部相乘*/ complex3.real=complex1.real * complex2.real
- complex1.image * complex2.image;
/*复数相乘的虚部:虚部与实部相乘 加上 实部与虚部相乘*/ complex3.image= complex1.real * complex2.image
+ complex1.image * complex2.real;
/*返回一个复数*/
return complex3;
}