-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob65.c
More file actions
25 lines (25 loc) · 685 Bytes
/
prob65.c
File metadata and controls
25 lines (25 loc) · 685 Bytes
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
//a program to add two complex numbers by passing structure to a function
#include<stdio.h>
typedef struct complex
{
float real;
float imag;
}complex;
complex add(complex n1,complex n2){
complex temp;
temp.real=n1.real+n2.real;
temp.imag=n1.imag+n2.imag;
return (temp);
}
int main(){
complex n1,n2,result;
printf("for 1st complex number\n");
printf("enter real and imaginary parts:\n");
scanf("%f %f", &n1.real,&n1.imag);
printf("\nfor 2nd complex number\n");
printf("enter real and imaginary parts:\n");
scanf("%f %f", &n2.real,&n2.imag);
result=add(n1,n2);
printf("sum=%.1f+%.1f",result.real,result.imag);
return 0;
}