The purpose of this assignment is to learn and use structure type and makefile.

You are to implement a program that will demonstrate complex number operations. The program is divided into several files: "complex.h", "complex.c", and "main.c". You should have a Makefile that will allow the user to type "make" to generate the executable "complex".


Here are some basic components for your program design.

First, in the Makefile, you should compile "complex.c" and "main.c" into object files separately, and make sure the object file depends on "complex.h" as well. In other words, if you modify "complex.h", both "complex.c" and "main.c" will be compiled again if you type "make". The final executable "complex" depends on linking "main.o" and "complex.o".

Second, in general, global variables and constants, structure definitions, and function prototypes are defined in the header file for inclusions. In "complex.h", you should have structure type definition for "complex_t" and function prototypes for "add_complex", "subtract_complex", "multiply_complex", "abs_complex", and "print_complex".

Third, in general, related functions are grouped/implemented in the same file. In "complex.c", implement all the functions related to complex number operations as defined in the prototypes. Remember, in addition to the system include files, you need to add #include "complex.h" in order to have the defined structure and function prototypes.

Finally, in the main program, you also form and display the multiplication of two complex numbers.

You will submit five files: (1) complex.h, complex.c, main.c, and Makefile; (2) a script file containing a sample run.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdlib.h>

#include "complex.h"

* Complex number input function return standard scanning error code
* 1 : valid code
* 0 : error code
* negative EOF value : end of file

int scan_complex(complex_t * c){
    int status;
    status = scanf("%lf%lf", &c->real, &c->imag);
    if (status == 2) {
       status = VALID_CODE;
    } else {
       status = ERROR_CODE;
    return (status);

* Complex output function display value as (a + bi) or (a - bi).
* dropping a or b if they round to 0 unless both round to 0

void print_complex(complex_t c){
    double a, b;
    char sign;
    a = c.real;
    b = c.imag;...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats