Question Solved1 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 - 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.  Reference: #include <stdio.h> // 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("\n"); } 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 .0 u \mathrm{t} \) \( 5.0-6.0 \) \( 3.02 .0 \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(8.00+-4.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})-(3.00+2.00 \mathrm{i})=(2.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(27.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i}) /(3.00+2.00 \mathrm{i})=(0.23+-2.15 \mathrm{i}) \)

Q3TKTI The Asker · Computer Science

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. 

Reference:

#include <stdio.h>

// 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("\n");
}

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;
}

Transcribed Image Text: \( \$ \) gcc ccalc.c \( \$ . / a .0 u \mathrm{t} \) \( 5.0-6.0 \) \( 3.02 .0 \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(8.00+-4.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})-(3.00+2.00 \mathrm{i})=(2.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(27.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i}) /(3.00+2.00 \mathrm{i})=(0.23+-2.15 \mathrm{i}) \)
More
Transcribed Image Text: \( \$ \) gcc ccalc.c \( \$ . / a .0 u \mathrm{t} \) \( 5.0-6.0 \) \( 3.02 .0 \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(8.00+-4.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})-(3.00+2.00 \mathrm{i})=(2.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i})+(3.00+2.00 \mathrm{i})=(27.00+-8.00 \mathrm{i}) \) \( (5.00+-6.00 \mathrm{i}) /(3.00+2.00 \mathrm{i})=(0.23+-2.15 \mathrm{i}) \)
See Answer
Add Answer +20 Points
Community Answer
RAQ1H2 The First Answerer
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

Step1/4.gkwtCW{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:16px;}/*!sc*/data-styled.g379[id="sc-z3f5s1-0"]{content:"gkwtCW,"}/*!sc*/.iIwMoS{white-space:pre-wrap;}/*!sc*/data-styled.g381[id="sc-1aslxm9-0"]{content:"iIwMoS,"}/*!sc*/.fzJtOB{text-align:start;}/*!sc*/data-styled.g383[id="sc-1aslxm9-2"]{content:"fzJtOB,"}/*!sc*/.hOZehF{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;}/*!sc*/data-styled.g410[id="sc-9wsboo-0"]{content:"hOZehF,"}/*!sc*/.lhIoTe{margin:0;font-size:1rem;}/*!sc*/data-styled.g412[id="sc-1swtczx-0"]{content:"lhIoTe,"}/*!sc*/.fCNNeF{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;font-size:0.75rem;box-sizing:border-box;}/*!sc*/data-styled.g432[id="sc-2n8uaj-0"]{content:"fCNNeF,"}/*!sc*/.cWhtxL{position:relative;}/*!sc*/data-styled.g433[id="sc-2n8uaj-1"]{content:"cWhtxL,"}/*!sc*/.cxYHbd::before{position:absolute;content:attr(data-line);color:rgba(60,60,60,0.5);top:0;bottom:0;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:flex-end;-webkit-box-align:flex-end;-ms-flex-align:flex-end;align-items:flex-end;}/*!sc*/data-styled.g434[id="sc-2n8uaj-2"]{content:"cxYHbd,"}/*!sc*/.fIiEuS{margin-left:2em;}/*!sc*/data-styled.g435[id="sc-2n8uaj-3"]{content:"fIiEuS,"}/*!sc*/.iJhZlT{background-color:#f7f7f7;}/*!sc*/.iJhZlT code[class*='language-'],.iJhZlT pre[class*='language-']{color:black;background:none;text-shadow:0 1px white;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}/*!sc*/.iJhZlT pre[class*='language-']::-moz-selection,.iJhZlT pre[class*='language-']::-moz-selection,.iJhZlT code[class*='language-']::-moz-selection,.iJhZlT code[class*='language-']::-moz-selection{text-shadow:none;background:#b3d4fc;}/*!sc*/.iJhZlT pre[class*='language-']::selection,.iJhZlT pre[class*='language-']::selection,.iJhZlT code[class*='language-']::selection,.iJhZlT code[class*='language-']::selection{text-shadow:none;background:#b3d4fc;}/*!sc*/@media print{.iJhZlT code[class*='language-'],.iJhZlT pre[class*='language-']{text-shadow:none;}}/*!sc*/.iJhZlT pre[class*='language-']{padding:1em;margin:0.5em 0;overflow:auto;}/*!sc*/.iJhZlT:not(pre) &gt; code[class*='language-'],.iJhZlT pre[class*='language-']{background:#f5f2f0;}/*!sc*/.iJhZlT:not(pre) &gt; code[class*='language-']{padding:0.1em;border-radius:0.3em;white-space:normal;}/*!sc*/.iJhZlT div,.iJhZlT span,.iJhZlT .token{font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;}/*!sc*/.iJhZlT .token.comment,.iJhZlT .token.prolog,.iJhZlT .token.doctype,.iJhZlT .token.cdata{color:slategray;}/*!sc*/.iJhZlT .token.punctuation{color:#999;}/*!sc*/.iJhZlT .token.namespace{opacity:0.7;}/*!sc*/.iJhZlT .token.property,.iJhZlT .token.tag,.iJhZlT .token.boolean,.iJhZlT .token.number,.iJhZlT .token.constant,.iJhZlT .token.symbol,.iJhZlT .token.deleted{color:#905;}/*!sc*/.iJhZlT .token.selector,.iJhZlT .token.attr-name,.iJhZlT .token.string,.iJhZlT .token.char,.iJhZlT .token.builtin,.iJhZlT .token.inserted{color:#690;}/*!sc*/.iJhZlT .token.operator,.iJhZlT .token.entity,.iJhZlT .token.url,.iJhZlT .language-css .token.string,.iJhZlT .style .token.string{color:#9a6e3a;}/*!sc*/.iJhZlT .token.atrule,.iJhZlT .token.attr-value,.iJhZlT .token.keyword{color:#07a;}/*!sc*/.iJhZlT .token.function,.iJhZlT .token.class-name{color:#dd4a68;}/*!sc*/.iJhZlT .token.regex,.iJhZlT .token.important,.iJhZlT .token.variable{color:#e90;}/*!sc*/.iJhZlT .token.important,.iJhZlT .token.bold{font-weight:bold;}/*!sc*/.iJhZlT .token.italic{font-style:italic;}/*!sc*/.iJhZlT .token.entity{cursor:help;}/*!sc*/data-styled.g436[id="sc-2n8uaj-4"]{content:"iJhZlT,"}/*!sc*/.iHelzO{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;line-height:normal;}/*!sc*/data-styled.g445[id="sc-1sugbjn-0"]{content:"iHelzO,"}/*!sc*/.kkKaFK{margin-top:14px;}/*!sc*/data-styled.g449[id="sc-1sugbjn-4"]{content:"kkKaFK,"}/*!sc*/.iQllJf{margin-top:14px;}/*!sc*/data-styled.g450[id="sc-1sugbjn-5"]{content:"iQllJf,"}/*!sc*/The following is the solution for the above given problem :here, we have to perform the arithmatic operations of the complex numbers.c1 = (x1 + y1 i) and c2 = (x2 + y2 i)c1 + c2c1 - c2c1 * c2c1 / c2Explanation:given that :c program should be named ccal.chaving 4 double arguments (x1,x2,y1,y2)result should be c1+c2, c1- c2, c1 * c2, c1 / c2where, c1 = (x1 + y1 i) and c2 = (x2 + y2 i)Step2/4.gkwtCW{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:16px;}/*!sc*/data-styled.g379[id="sc-z3f5s1-0"]{content:"gkwtCW,"}/*!sc*/.iIwMoS{white-space:pre-wrap;}/*!sc*/data-styled.g381[id="sc-1aslxm9-0"]{content:"iIwMoS,"}/*!sc*/.fzJtOB{text-align:start;}/*!sc*/data-styled.g383[id="sc-1aslxm9-2"]{content:"fzJtOB,"}/*!sc*/.hOZehF{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;}/*!sc*/data-styled.g410[id="sc-9wsboo-0"]{content:"hOZehF,"}/*!sc*/.lhIoTe{margin:0;font-size:1rem;}/*!sc*/data-styled.g412[id="sc-1swtczx-0"]{content:"lhIoTe,"}/*!sc*/.fCNNeF{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;font-size:0.75rem;box-sizing:border-box;}/*!sc*/data-styled.g432[id="sc-2n8uaj-0"]{content:"fCNNeF,"}/*!sc*/.cWhtxL{position:relative;}/*!sc*/data-styled.g433[id="sc-2n8uaj-1"]{content:"cWhtxL,"}/*!sc*/.cxYHbd::before{position:absolute;content:attr(data-line);color:rgba(60,60,60,0.5);top:0;bottom:0;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:flex-end;-webkit-box-align:flex-end;-ms-flex-align:flex-end;align-items:flex-end;}/*!sc*/data-styled.g434[id="sc-2n8uaj-2"]{content:"cxYHbd,"}/*!sc*/.fIiEuS{margin-left:2em;}/*!sc*/data-styled.g435[id="sc-2n8uaj-3"]{content:"fIiEuS,"}/*!sc*/.iJhZlT{background-color:#f7f7f7;}/*!sc*/.iJhZlT code[class*='language-'],.iJhZlT pre[class*='language-']{color:black;background:none;text-shadow:0 1px white;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;}/*!sc*/.iJhZlT pre[class*='language-']::-moz-selection,.iJhZlT pre[class*='language-']::-moz-selection,.iJhZlT code[class*='language-']::-moz-selection,.iJhZlT code[class*='language-']::-moz-selection{text-shadow:none;background:#b3d4fc;}/*!sc*/.iJhZlT pre[class*='language-']::selection,.iJhZlT pre[class*='language-']::selection,.iJhZlT code[class*='language-']::selection,.iJhZlT code[class*='language-']::selection{text-shadow:none;background:#b3d4fc;}/*!sc*/@media print{.iJhZlT code[class*='language-'],.iJhZlT pre[class*='language-']{text-shadow:none;}}/*!sc*/.iJhZlT pre[class*='language-']{padding:1em;margin:0.5em 0;overflow:auto;}/*!sc*/.iJhZlT:not(pre) &gt; code[class*='language-'],.iJhZlT pre[class*='language-']{background:#f5f2f0;}/*!sc*/.iJhZlT:not(pre) &gt; code[class*='language-']{padding:0.1em;border-radius:0.3em;white-space:normal;}/*!sc*/.iJhZlT div,.iJhZlT span,.iJhZlT .token{font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;}/*!sc*/.iJhZlT .token.comment,.iJhZlT .token.prolog,.iJhZlT .token.doctype,.iJhZlT .token.cdata{color:slategray;}/*!sc*/.iJhZlT .token.punctuation{color:#999;}/*!sc*/.iJhZlT .token.namespace{opacity:0.7;}/*!sc*/.iJhZlT .token.property,.iJhZlT .token.tag,.iJhZlT .token.boolean,.iJhZlT .token.number,.iJhZlT .token.constant,.iJhZlT .token.symbol,.iJhZlT .token.deleted{color:#905;}/*!sc*/.iJhZlT .token.selector,.iJhZlT .token.attr-name,.iJhZlT .token.string,.iJhZlT .token.char,.iJhZlT .token.builtin,.iJhZlT .token.inserted{color:#690;}/*!sc*/.iJhZlT .token.operator,.iJhZlT .token.entity,.iJhZlT .token.url,.iJhZlT .language-css .token.string,.iJhZlT .style .token.string{color:#9a6e3a;}/*!sc*/.iJhZlT .token.atrule,.iJhZlT .token.attr-value,.iJhZlT .token.keyword{color:#07a;}/*!sc*/.iJhZlT .token.function,.iJhZlT .token.class-name{color:#dd4a68;}/*!sc*/.iJhZlT .token.regex,.iJhZlT .token.important,.iJhZlT .token.variable{color:#e90;}/*!sc*/.iJhZlT .token.important,.iJhZlT .token.bold{font-weight:bold;}/*!sc*/.iJhZlT .token.italic{font-style:italic;}/*!sc*/.iJhZlT .token.entity{cursor:help;}/*!sc*/data-styled.g436[id="sc-2n8uaj-4"]{content:"iJhZlT,"}/*!sc*/.iHelzO{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;line-height:normal;}/*!sc*/data-styled.g445[id="sc-1sugbjn-0"]{content:"iHelzO,"}/*!sc*/.kkKaFK{margin-top:14px;}/*!sc*/data-styled.g449[id="sc-1sugbjn-4"]{content:"kkKaFK,"}/*!sc*/.iQllJf{margin-top:14px;}/*!sc*/data-styled.g450[id="sc-1sugbjn-5"]{content:"iQllJf,"}/*!sc*/the given reference program is little bit confusing, so with the same concept we can do the same as follows :------------------------------------------------------------------------------------------------------------------------------------------------first of all the header file#include &lt;stdio.h&gt;define the struct ComplexNumber{} as follows :typedef struct ComplexNumber { float r; //real part float i; //imaginary part} complex;and define the cadd, csub, cmul and cdiv with the complex keyword besed on the above struct defintion as follows :complex cadd(complex c1, complex c2);complex csub(complex c1, complex c2);complex cmul(complex c1, complex c2);complex cdiv(complex c1, complex c2);Explanation:Please refer to solution in this step.Step3/4.gkwtCW{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:16px;}/*!sc*/data-styled.g379[id="sc-z3f5s1-0"]{content:"gkwtCW,"}/*!sc*/.iIwMoS{white-space:pre-wrap;}/*!sc*/data-styled.g381[id="sc-1aslxm9-0"]{content:"iIwMoS,"}/*!sc*/.fzJtOB{text-align:start;}/*!sc*/data-styled.g383[id="sc-1aslxm9-2"]{content:"fzJtOB,"}/*!sc*/.hOZehF{margin:0;font-family:"Aspira W ... See the full answer