Sunday 15 December 2013

C Program to Add two Complex Numbers

#include < stdio.h>
 
struct complex
{
   int realpart, imaginary;
};
 
main()
{
    struct complex a, b, c;
 
    printf("Enter value of a and b complex number a + ib.\n");
    printf("value of complex number a is = ");
    scanf("%d", &a.realpart);
    printf("value of complex number b is = ");
    scanf("%d", &a.imaginary);
    printf("Enter value of c and d complex number c + id.\n");
    printf("value of complex number c is = ");
    scanf("%d", &b.realpart);
    printf("value of complex number d is = ");
    scanf("%d", &b.imaginary);
    c.realpart = a.realpart + b.realpart;
    c.imaginary = a.imaginary + b.imaginary;
    if (c.imaginary >= 0)
        printf("complex numbers sum is = %d + %di\n", c.realpart, c.imaginary);
    else
        printf("complex numbers sum = %d %di\n", c.realpart, c.imaginary);
    return 0;
}

Output

 Enter value of a and b complex number a + ib.
value of complex number a is =  10 
value of complex number b is =  12 
Enter value of c and d complex number c + id.
value of complex number c is =  15 
value of complex number d is =  22 
complex numbers  sum  is =  25  + 34i

For More Details Please Visit Ictjobs.info

No comments: