Write a program to print absolute vlaue of a number entered by user. E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1
using python
Answers
Answered by
3
number = int(input("Enter a number: "))
print(abs(number))
Answered by
1
Answer:
#include <iostream>
using namespace std;
int main(){
int a;
cin>>a;
if(a<0){
cout<<-1*a;
}
else{
cout<<a;
}
return 0;
}
Explanation:
simple answer for c++ language if the value is less than 0 means it is negative so we multiply it with -1 to make it positive otherwise if value is in positive means its already and absolute value so just print out the same number simple as that. hope you understood
Similar questions