A complex number is a number that can be expressed in the form a + bi, where a a
ID: 3787403 • Letter: A
Question
A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, Squareroot -1 or i^2 = -1. In this expression, a is the real part and b is the imaginary part of the complex number. Give two complex numbers, a + bi and c + di, you can perform addition, subtraction, multiplication, and division using the following formulas: a + bi + c + di = (a + c) + (b + d)i Eq. 1 a + bi - (c + di) = (a - c) + (b - d)i Eq. 2 (a + bi) * (c + di) = (ac - bd) + (be + ad)i Eq. 3 (a + bi)/(c + di) = (ac + bd)/(c^2 + d^2) + (be - ad)i/(c^2 + d^2) Eq. 4 Write a program capable of performing complex arithmetic using equations 1 to 4. Your program should contain; Four functions: Given real numbers a, b, c, and d The add(a, b, c, d}function should output the sum of two complex numbers based on eq. 1. The sub(a, b, c, d)function should output the difference of two complex numbers based on eq. 2. The mult(a, b, c, d)function should output the product of two complex numbers based on eq. 3. The div(a, b, c, d)function should output the division of two complex numbers based on eq. 4. Main functions: In the main function, your program should prompt users for the two complex numbers (a, b, c, and d) and the mathematical operation they would like to perform and displays the result of the operation to the screen. In addition, your program should use a while or do...while statement to check whether the user would like to quit or continue performing further computation.Explanation / Answer
Solution for Problem (in C program Functions)
Program :-
#include<stdio.h>
float The_add(float a,float b,float c,float d);
float The_sub(float a,float b,float c,float d);
float The_mult(float a,float b,float c,float d);
float The_div(float a,float b,float c,float d);
int main()
{
int i;
do
{
float a,b,c,d;
printf("Enter any 4 real numbers :- ");
scanf("%f%f%f%f",&a,&b,&c,&d);
printf("The addition of complex number : %f ",The_add(a,b,c,d));
printf("The subtraction of complex number : %f ",The_sub(a,b,c,d));
printf("The multiplication of complex number : %f ",The_mult(a,b,c,d));
printf("The division of complex number : %f ",The_div(a,b,c,d));
printf("Do you want to Continue Press 1 :-");
scanf("%d",&i);
}while(i==1);
return 0;
}
float The_add(float a,float b,float c,float d)
{
return (a+c)+(b+d);
}
float The_sub(float a,float b,float c,float d)
{
return (a-c) + (b-d);
}
float The_mult(float a,float b,float c,float d)
{
return ((a*c)-(b*d)) + ((b*c)+(a*d));
}
float The_div(float a,float b,float c,float d)
{
return (((a*c) + (b*d))) / ((c*c)+(d*d)) + (((b*c) - (a*d)) / ((c*c)+(d*d)));
}
Output :-
Enter any 4 real numbers :- 2.5
5.6
8.2
6.2
The addition of complex number : 22.500000
The subtraction of complex number : -6.300000
The multiplication of complex number : 47.199999
The division of complex number : 0.810371
Do you want to Continue Press 1 :-1
Enter any 4 real numbers :-
Note :- For quit you can press any any number but for continue press 1.When you give other then 1 it quits.
Thank you!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.