-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplexCode.txt
More file actions
71 lines (52 loc) · 1.25 KB
/
complexCode.txt
File metadata and controls
71 lines (52 loc) · 1.25 KB
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
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include "stdafx.h"
#include "conio.h"
struct TComplex {
float re;
float im;
};
void PrintComplex(struct TComplex anumber)
{
printf("%f%+fi\n",anumber.re,anumber.im);
}
struct TComplex GetComplex1()
{
struct TComplex localV;
printf("Enter real part of number 1\n");
scanf_s("%f",&localV.re);
printf("Enter imaginary part of number 1\n");
scanf_s("%f",&localV.im);
return localV;
}
struct TComplex GetComplex2()
{
struct TComplex localV;
printf("Enter real part of number 2\n");
scanf_s("%f",&localV.re);
printf("Enter imaginary part of number 2\n");
scanf_s("%f",&localV.im);
return localV;
}
struct TComplex AddComplex(struct TComplex num1, struct TComplex num2)
{
struct TComplex sum;
sum.im = num1.im + num2.im;
sum.re = num1.re + num2.re;
return sum;
}
int _tmain(int argc, _TCHAR* argv[])
{
struct TComplex mynumber1;
mynumber1 = GetComplex1();
struct TComplex mynumber2;
mynumber2 = GetComplex2();
struct TComplex sumnum;
sumnum = AddComplex(mynumber1,mynumber2);
printf("(%f%+fi)+(%f%+fi)\n",mynumber1.re,mynumber1.im,mynumber2.re,mynumber2.im);
PrintComplex(sumnum);
getchar();
getchar();
return 0;
}