Assignments » Flow Of Control » Set1 » Solution 2

Find the absolute value of a number entered by the user.

 

#include<iostream>
using namespace std;


int main()
{
	int a;
	cout<<"Enter any number:";
	cin>>a;

	if(a>0)
		cout<<"The absolute value of number is:"<<a;
	else
		cout<<"The absolute value of number is:"<<-(a);


	return 0;
}

 

 

SAMPLE RUN # 1

Enter any number:-57
The absolute value of number is:57

SAMPLE RUN # 2

Enter any number:50
The absolute value of number is:50