Question: A. Modify the above program so that the addition of two complex numbers will be done in a function instead of doing it in the

 A. Modify the above program so that the addition of twocomplex numbers will be done in a function instead of doing it

A. Modify the above program so that the addition of two complex numbers will be done in a function instead of doing it in the main function. Bellow the function frame: struct complex add(struct complex z1, struct complex 22) { struct sum; 1/Add your code here return sum; } B. Modify your code by adding separate functions to compute the difference between the two complex numbers, the product of the two complex numbers, and the result of dividing the first complex number by the second complex number. Hint: consider the two complex numbers The difference between the two numbers is (real1 - real2) + (imag1 - imag2) The product of the two numbers is (real1*real2 -imag1*imag2 ) + (real1*imag2+ real2*imag1) i The division of the first complex number by the second complex number is given by: real1 * real2 + imag1 * imag2 /real2 * imag1 real1 * imag2 + real22 + imag22 real22 + imag22 i The program below use the above mentioned complex number definition and asks the user to enter two complex numbers, adds the two numbers, and displays the sum. #include struct complex { float re;// The real part float im; // The imaginary part }; int main() { struct complex complex1, complex2, sum; printf("Enter the first complex number "); printf("Enter the real part "); scanf( "%f", &complex1.re ); printf("Enter the imaginary part " ); scanf("%f", &complex1.im ); printf("Enter the second complex number "); printf("Enter the real part "); scanf("%f", &complex2.re); printf("Enter the imaginary part "); scanf("%f", &complex2.im ); sum.re = complex1.re + complex2.re; sum.im = complex1.im + complex2.im; // show the sum printf("Sum is (%f, %fi) ", sum.re, sum.im); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!