Absolute Value
Learn to write multiple functions for finding absolute values.
We'll cover the following
Challenge
Write a program that implements multiple versions of theabso( )
function to find the absolute value of int
, float
, long int
, double
, and long double
.
For this problem, you will have to write five functions:
1. int abso ( int )
This function takes an int as an argument and returns its absolute value as an int.
2. long int abso ( long int )
This function takes a long int as a function parameter and returns its absolute long int value.
3. float abso ( float )
It takes a float as an argument and returns its absolute float value.
4. double abso ( double )
This function takes a double value as an argument and returns its absolute value as a double.
5. long double abso ( long double )
This function accepts a long double as a function argument and returns its absolute value as a long double.
Coding exercise
Try to solve this challenge on your own. If you can’t solve it, you can look at the solution and explanation below.
Get hands-on with 1400+ tech skills courses.