Wednesday, 23 April 2014

25. Define a structure that will hold the data for a complex number. Using this structure, please write a program that will input two complex numbers and output the multiple of the two complex numbers. Use double variables to represent complex number components. Note: A complex number z is a number of the form z = a + bi where a and bare real numbers. The term a is called the real part of Z and b is called the imaginary part of z. The multiplication operation on complex numbers is defined as: (a + hi) * (c + di) = (ac -bd) + (ad + bc)i



# include<stdio.h>
#include<conio.h> void main()
{
double temp1,temp2; struct complexnum { double realpart; double imagpart;
} compnum[2];
clrscr();
printf("Complex Number1\nEnter Real Part :"); scanf("%lf",&compnum[0].realpart); printf("Enter Imaginary Part :");
scanf("%lf", &compnum[0].imagpart); printf("\nComplex Number2\nEnter Real Part :"); scanf("%lf",&compnum[1].realpart); printf("Enter Imaginary Part :");
scanf("%lf", &compnum[1].imagpart);
printf("\nThe Product of Complex No. 1 and Complex No. 2 is :"); temp1=(compnum[0].realpart * compnum[1].realpart) - (compnum[0].imagpart * compnum[1].imagpart);
temp2=(compnum[0].realpart * compnum[1].imagpart) + (compnum[0].imagpart * compnum[1].realpart);
printf("%.2lf + %.2lf i",temp1,temp2); getch();
}

No comments:

Post a Comment