Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribed

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

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions