Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAMING! My code does not match the output very well and I don't know how to fix it. Help would be appreciated! [Example of

C PROGRAMING! My code does not match the output very well and I don't know how to fix it. Help would be appreciated!

[Example of input] 2 3.08 -2.04 5.06 [Output example] (2.0+3.1i) + (-2.0+5.1i) = 8.1i (2.0+3.1i) - (-2.0+5.1i) = 4.0-2.0i (2.0+3.1i) * (-2.0+5.1i) = -19.7+3.8i (2.0+3.1i) / (-2.0+5.1i) = 0.4-0.6i

My code:

#include typedef struct complex { float real; float imag; } complex;

complex add(complex n1, complex n2); complex sub(complex n1, complex n2); complex mul(complex n1, complex n2); complex divi( complex n1, complex n2); int main() { complex n1, n2, result;

scanf("%f %f %f %f", &n1.real, &n1.imag,&n2.real, &n2.imag);

result = add(n1, n2); printf("(%.1f+%.1fi)+(%.1f+%.1fi) = %.1f + %.1fi ", n1.real, n1.imag, n2.real, n2.imag, result.real, result.imag); result= sub(n1,n2); printf("(%.1f+%.1fi)-(%.1f+%.1fi) = %.1f + %.1fi ", n1.real, n1.imag, n2.real, n2.imag,result.real, result.imag); result = mul(n1,n2); printf("(%.1f+%.1fi)*(%.1f+%.1fi) = %.1f + %.1fi ", n1.real, n1.imag, n2.real, n2.imag,result.real, result.imag); result = divi(n1,n2); printf("(%.1f+%.1fi)/(%.1f+%.1fi) = %.1f + %.1fi ",n1.real, n1.imag, n2.real, n2.imag, result.real, result.imag); return 0; }

complex add(complex n1, complex n2) { complex temp; temp.real = n1.real + n2.real; temp.imag = n1.imag + n2.imag; return (temp); } complex sub(complex n1, complex n2){ complex temp; temp.real=n1.real-n2.real; temp.imag=n1.imag-n2.imag; return(temp); } complex mul(complex n1, complex n2){ complex temp; temp.real=(n1.real*n2.real)-(n1.imag*n2.imag); temp.imag=(n1.imag*n2.real)+(n1.real*n2.imag); return(temp);}

complex divi( complex n1, complex n2){ complex temp; temp.real=((n1.real*n2.real)+(n1.imag*n2.imag))/(n2.real*n2.real+n2.imag*n2.imag); temp.imag=((n1.imag*n2.real)-(n1.real*n2.imag))/(n2.real*n2.real+n2.imag*n2.imag); return(temp);}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

=+you think is being taxed when more money is printed? Why?

Answered: 1 week ago