Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started