-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complex_Number.c
47 lines (43 loc) · 1016 Bytes
/
Complex_Number.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
#include <stdio.h>
#include <stdlib.h>
//Complex Number -- a+bi
typedef struct{
float a;
float b;
}complex;
int main(){
complex n1;
complex n2;
complex sonuc;
char op;
printf("Birinci karmasik sayiyi giriniz: ");
scanf("%f%f",&n1.a,&n1.b);
printf("Ikinci karmasik sayiyi giriniz: ");
scanf("%f%f",&n2.a,&n2.b);
printf("Operator giriniz(+ -): ");
scanf(" %c",&op);
if(op=='+'){
sonuc.a = n1.a + n2.a;
sonuc.b = n1.b + n2.b;
if(sonuc.b>=0){
printf("Sonuc: %.2f+%.2fi",sonuc.a,sonuc.b);
}
else{
printf("Sonuc: %.2f%.2fi",sonuc.a,sonuc.b);
}
}
else if(op=='-'){
sonuc.a = n1.a - n2.a;
sonuc.b = n1.b - n2.b;
if(sonuc.b>=0){
printf("Sonuc: %.2f+%.2fi",sonuc.a,sonuc.b);
}
else{
printf("Sonuc: %.2f%.2fi",sonuc.a,sonuc.b);
}
}
else{
printf("Gecersiz operator girdiniz!");
}
return 0;
}