Showing posts with label complex number multiplication. Show all posts
Showing posts with label complex number multiplication. Show all posts

Monday 13 February 2017

C program using structure

Structure is an extended data type in C. Structure is a collection of related data of different data types. The following program shows how to work with complex numbers using structure in C.

#include<stdio.h>
#include<conio.h>
struct complex
{
 int r,i;
};
struct complex c1,c2,c3;
main()
{
 clrscr();
 printf("Enter the first complex number\n");
 scanf("%d%d",&c1.r,&c1.i);
 printf("The first complex number is\n");
 printf("%d+i%d\n",c1.r,c1.i);
 printf("Enter the second complex number\n");
 scanf("%d%d",&c2.r,&c2.i);
 printf("The second complex number is\n");
 printf("%d+i%d\n",c2.r,c2.i);
 c3.r=c1.r+c2.r;
 c3.i=c1.i+c2.i;
 printf("The result of addition of two complex numbers is\n");
 printf("%d+i%d\n",c3.r,c3.i);
 c3.r=(c1.r*c2.r)-(c1.i*c2.i);
 c3.i=(c1.i*c2.r)+(c1.r*c2.i);
 printf("The result of multiplication of two complex numbers is\n");
 printf("%d+i%d\n",c3.r,c3.i);
 getch();
}
*/
OUTPUT:
_______
Enter the first complex number
4 6
The first complex number is
4+i6
Enter the second complex number
1 9
The second complex number is
1+i9
The result of addition of two complex numbers is
5+i15
The result of multiplication of two complex numbers is
-50+i42