Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct comp
- {
- float real;
- float imag;
- }; struct comp comp1,comp2;
- struct comp sum_complex(struct comp complex1,struct comp complex2)
- {
- struct comp temp;
- temp.real = complex1.real + complex2.real;
- temp.imag = complex1.imag + complex2.imag;
- return temp;
- }
- int main()
- {
- struct comp result;
- printf("Enter Complex Number 1:-\n");
- scanf("%f%f",&comp1.real, &comp1.imag);
- printf("Enter Complex Number 2:\n");
- scanf("%f%f",&comp2.real,&comp2.imag);
- result = sum_complex(comp1,comp2);
- printf("The sum is %.2f + i%.2f\n\n", result.real,result.imag);
- return 0;
- }
- //output
- //Enter Complex Number 1:-
- //5
- //7
- //Enter Complex Number 2:
- //9
- //4
- //The sum is 14.00 + i11.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement