Thursday, January 8, 2015

Addition of complex numbers(C coding)

 BASIC  C  PROGRAMS :-



  • addition of  complex numbers-
#include<conio.h>
#include<stdlib.h>
struct complex
{
       int real;
       int img;
       };
       int main()
       {
           struct complex a,b,c;
           printf("Enter a and b where a+ib is the first complex number");
           printf("\na=");
           scanf("%d",&a.real);
           printf("b=");
           scanf("%d",&a.img);
           printf("Enter c and d where c+id is the second complex number.");
           printf("\nc=");
           scanf("%d",&b.real);
           printf("d=");
           scanf("%d",&b.img);
           c.real=a.real+b.real;
           c.img=a.img+b.img;
           if(c.img>=0)
           printf("sum of two complex numbers=%d+%di",c.real,c.img);
           else
           printf("sum of two complex numbers=%d%di",c.real,c.img);
           getch();
           return 0;
           }

output:-


please comment if you have any problem with this coding.

           

No comments: