Advertisement
Shailrshah

Addition of Complex Numbers

Apr 19th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. struct comp
  4. {
  5.  
  6.     float real;
  7.  
  8.     float imag;
  9.  
  10. }; struct comp comp1,comp2;
  11.  
  12. struct comp sum_complex(struct comp complex1,struct comp complex2)
  13. {
  14.  
  15.     struct comp temp;
  16.  
  17.     temp.real = complex1.real + complex2.real;
  18.  
  19.     temp.imag = complex1.imag + complex2.imag;
  20.  
  21.     return temp;
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27.  
  28.     struct comp result;
  29.  
  30.     printf("Enter Complex Number 1:-\n");
  31.  
  32.     scanf("%f%f",&comp1.real, &comp1.imag);
  33.  
  34.     printf("Enter Complex Number 2:\n");
  35.  
  36.     scanf("%f%f",&comp2.real,&comp2.imag);
  37.  
  38.     result = sum_complex(comp1,comp2);
  39.  
  40.     printf("The sum is %.2f + i%.2f\n\n", result.real,result.imag);
  41.  
  42.     return 0;
  43.  
  44. }
  45. //output
  46. //Enter Complex Number 1:-
  47. //5
  48. //7
  49. //Enter Complex Number 2:
  50. //9
  51. //4
  52. //The sum is 14.00 + i11.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement