Question
Please use C language. Extend your module: Extend your myMath module such that it includes a new function that calculates the hypotenuse (c) of a
Please use C language.
Extend your module: Extend your myMath module such that it includes a new function that calculates the hypotenuse (c) of a right-angle triangle given the other two sides of the triangle (a and b). An example of the Pythagorean theorem is given below.
The function for calculating c should take the form:
double pythag( int a, int b )
This function will accept two integers and treat them as the two sides (a, b) of a right-angle triangle and return the length (c) of the hypotenuse. To do so you will want to use the square root and maybe the power functions from the math.h library. The calculation for c is as follows:
Note that to use the functions in math.h you will need to include the compiler flag -lm at the end of your compile statement, so you will need to modify your makefile appropriately. Why?
Conditional compilation: To make this code more interesting, I want you to add an option via conditional compilation where, if debugging is turned on, then instead of using the pythag function, your main function uses macros to calculate the value for the hypotenuse (c) instead. To achieve this, you need to write macros that take parameters for ADD, SQRT, and POW. Build your code with conditional compilation so that when the -DDEBUG flag is used, then the three macros are used instead of the pythag function. Modify your makefile so that it has a debug target that turns on the -DDEBUG flag. When the -DDEBUG flag is turned on, the program should print out "In debugging mode..." as a part of the menu options.
hypotenuse C 9.43 a 5 b 8 8 2 c = Va+b
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started