Complex Absolute
In this activity
you need to complete the function complexAbsolute
in the provided program.
Download
complexAbs.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week06/files/complexAbs.c .
In this exercise you have been provided with a struct
to represent a Complex Number, called complex
.
Read the provided file
and understand the given data structure.
You have also been given a main
function and an incomplete
double complexAbsolute(complex c)
.
You must edit this function so that it returns the
magnitude/absolute value of the complex number it has been given.
The formula for the magnitude of a complex number is
We’ve #include
d a new header file, <math.h>
.
This declares a function, double sqrt(double x)
,
which returns the square root of x
.
Some Examples
Enter the real part: 3 Enter the imaginary part: 4 The absolute value is 5.00.
Enter the real part: 17 Enter the imaginary part: 17 The absolute value is 24.04.
To run some simple automated tests:
$ 1511 autotest complexAbs
To run Styl-o-matic:
$ 1511 stylomatic complexAbs.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk06_complexAbs
Or, if you are working from home, upload the relevant file(s) to the wk06_complexAbs activity on Give Online.