Question: Make a C program ccalc.c which takes 4 double arguments (x1, x2, y1 and y2). It outputs the calculation result c1 + c2, c1 -

Make a C program ccalc.c which takes 4 double arguments (x1, x2, y1 and y2). It outputs the calculation result c1 + c2, c1 - c2, c1 * c2, c1 / c2, where c1 = (x1 + y1 i) and c2 = (x2 + y2 i);

NOTE: You should declare a struct named ComplexNumber. Then you should define functions, cadd, csub, cmul and cdiv. The arguments of these functions must be ComplexNumber type. You must be able to get the outputs below. Make a C program ccalc.c which takes 4 double arguments (x1, x2,

Reference:

#include

// Define CompleNumber struct

// cadd struct ComplexNumber cadd(struct ComplexNumber c1, struct ComplexNumber c2) { }

// csub

// cmul

// cdiv

// Define necessary functions here...

void printFormula(char* operator, struct ComplexNumber c1, struct ComplexNumber c2, struct ComplexNumber result) { printComplexNumber(c1); printf(" %s ", operator); printComplexNumber(c2); printf(" = "); printComplexNumber(result); printf(" "); }

int main(int argc, char** argv) { struct ComplexNumber c1 = readComplexNumber(); struct ComplexNumber c2 = readComplexNumber();

// Add struct ComplexNumber ca = cadd(c1, c2); printFormula("+", c1, c2, ca);

// Subtraction

// Multiplication

// Division

return 0; }

$ gcc ccalc.c $./a.0ut 5.06.0 3.02.0 (5.00+6.00i)+(3.00+2.00i)=(8.00+4.00i) (5.00+6.00i)(3.00+2.00i)=(2.00+8.00i) (5.00+6.00i)+(3.00+2.00i)=(27.00+8.00i) (5.00+6.00i)/(3.00+2.00i)=(0.23+2.15i)

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!