Addition Of Two Complex Numbers


C Program For Addition Of Two Complex Numbers Source Code: #include<stdio.h> #include<conio.h> struct complex { int real,img; }; struct complex add(struct complex c1,struct complex c2); void main() { struct complex c1,c2,c3; clrscr(); printf("Enter 1st num:"); scanf("%d+i%d",&c1.real,&c1.img); printf("Enter 2nd num:"); scanf("%d+i%d",&c2.real,&c2.img); c3=add(c1,c2); if(c3.img<0) printf("Result=%d-i%d",c3.real,-c3.img); else printf("Result=%d+i%d",c3.real,c3.img); getch(); } struct complex add(struct complex c1,struct complex c2) { struct complex c3; c3.real=c1.real+c2.real; c3.img=c1.img+c2.img; return c3; }

Share:

0 comments