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


Find the absolute value of a number entered by the user.
Write c++ code to find absolute value.
Write a c++ program to find absolute value .
 
#include<iostream.h>
#include<conio.h>
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);
 
       getch();
       return 0;
}
Output:


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

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

No comments:

Post a Comment