-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.3_test.c
102 lines (98 loc) · 2.28 KB
/
5.3_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
typedef struct
{
int Realpart;
int Imagepart;
}Complex;
float ComplexMul(Complex* A, Complex* B);
float ComplexMul(Complex* A, Complex* B)
{
return (A->Realpart + A->Imagepart) * (B->Realpart + B->Imagepart);
}
int main()
{
Complex A = { 8, 6 };
Complex B = { 4, 3 };
/*printf("%f %f\n",A.Realpart, A.Imagepart);*/
float mul = ComplexMul(&A, &B);
printf("%f\n", mul);
return 0;
}
//typedef struct
//{
// float Realpart; //实部
// float Imagepart; // 虚部
//}Complex; //复数
//
////函数声明
//void Create(Complex* C, float x, float y);
//void Create1(Complex* C, float x, float y);
//float GetReal(Complex* C);
//float GetImage(Complex* C);
//void ComplexAdd(Complex* sum, Complex* C, Complex* C1);
//void ComplexSub(Complex* sub, Complex* C, Complex* C1);
//
////构造一个复数
//void Create(Complex* C, float x, float y)
//{
// C->Realpart = 3.14;
// C->Imagepart = 6.27;
//}
//
//void Create1(Complex* C1, float x, float y)
//{
// C1->Realpart = 5.21;
// C1->Imagepart = 7.86;
//}
//
////取复数的实部
//float GetReal(Complex* C)
//{
// return C->Realpart;
//}
//
////取复数的虚部
//float GetImage(Complex* C)
//{
// return C->Imagepart;
//}
////求两个复数的和
//void ComplexAdd(Complex* sum, Complex* C, Complex* C1)
//{
// sum->Realpart = C->Realpart + C1->Realpart;
// sum->Imagepart = C->Imagepart + C1->Imagepart;
// /*return sum;*/
//}
////求两复数的差
//void ComplexSub(Complex* sub, Complex* C, Complex* C1)
//{
// sub->Realpart = C->Realpart - C1->Realpart;
// sub->Imagepart = C->Imagepart - C1->Imagepart;
//
//}
//int main()
//{
// Complex C = { 0 };
// Complex C1 = { 0 };
// float GReal = 0;
// float GImage = 0;
// Complex sum = { 0 };
// Complex sub = { 0 };
//
// Create(&C, C.Realpart, C.Imagepart);//构造复数
// /*printf("%f %f",C.Realpart, C.Imagepart);*/
// Create1(&C1, C.Realpart, C.Imagepart);
//
// GReal = GetReal(&C);//取复数的实部
// /*printf("%f\n", GReal);*/
// GImage = GetImage(&C);//取复数的虚部
// ComplexAdd(&sum, &C, &C1);//求两个复数的和
// /*printf("%f %f", sum.Realpart, sum.Imagepart);*/
// ComplexSub(&sub, &C, &C1);//求差
// printf("%f %f", sub.Realpart, sub.Imagepart);
//
// return 0;
//}