Question

using C++ in beginner form Create a function named absoluteValue that takes in a number and...

using C++ in beginner form

Create a function named absoluteValue that takes in a number and returns the absolute value of it (e.g. if it takes in 5 or -5 it will return 5)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

input code:

output:

code:

#include <iostream>
using namespace std;
/*make method*/
int absoulevalue(int n)
{
/*if n<0 than multiply with -1*/
if(n<0)
{
return -1*n;
}
else
{
/*else return as it is*/
return n;
}
}
int main()
{
/*declare the variables*/
int n;
/*take input from user*/
cout<<"Enter the n:";
cin>>n;
/*call method*/
n=absoulevalue(n);
/*print output*/
cout<<"output is:"<<n;
return 0;
}
  

Add a comment
Know the answer?
Add Answer to:
using C++ in beginner form Create a function named absoluteValue that takes in a number and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT