Concept is 'If a number's value is < 0 then its positive equivalent is returned or else the number is returned as it.
For value=0, the number is returned as is' that means 0 is return.
Examples:
- If n = -10 then its absolute value will be 10.
- If n = 10 then its absolute value will be 10.
- If n = 0 then its absolute value will be 0. Following implementation find a number's absolute value.
void int findAbsoluteValue(int n)
{
if(n < 0)
return n*-1;
else
return n;
}
You might also like:
Find White Spaces in Character Array
Find a character in the String
Number is prime or not
Notes on Sorting and Searching Algorithms
Common String Functions
Reverse a String
Product of all array location expect its own
Find a cycle in the Linked List
Find a binomial co-efficient
Remove duplicates from the array
Telephonic phone technical interview questions - Part 2
Counting sort algorithm
B-Tree
No comments:
Post a Comment