Monday, 3 June 2013

Sum of Two Complex Numbers in C

  C99 has a header file called <complex.h> which contains functions and macros to manipulate complex numbers. C99 also adds _Complex keyword to deal with complex numbers. But in this small program I have used C89 syntax and double data type to deal with complex numbers.

#include<stdio.h>
int main()
{
    double re1,im1,re2,im2,re3,im3;
    printf("\n\nThe format of Complex Number is a+bi\n\n");
    printf("\nEnter the First Complex number:  ");
    scanf("%lf+%lfi",&re1,&im1);
    printf("\nEnter the Second Complex number:  ");
    scanf("%lf+%lfi",&re2,&im2);
    re3=re1+re2;
    im3=im1+im2;
    printf("\nThe Sum = %lf+%lfi\n",re3,im3);
    return 0;
}



 
Figure Below Shows a Sample Output
 

No comments:

Post a Comment