Hello I'm still just starting out in programming and I have a small problem... I want to know what to write to create a program that asks for the absolute value of a number... Thank you for replying quickly.
Hi, In most programming languages, there is a predefined function in that language that returns an absolute value: If you use the C language, it would normally look like (if I remember the exact syntax correctly): absolute_number=abs(number). Of course, an absolute number is the positive value of the number in question.
Thank you for your help....but what this little problem is about the C language and I was told that I need to use if and else. I don't know how, but thank you anyway for your help..
In fact, the absolute value of a number is the number itself without the sign. Saying that it is the positive value of the number implies a notion of relativity.
Hello and welcome to the world of programming. I'm happy to respond to you because I am also, like you, a pretentious beginner. Here’s a little code that you can try as simply as possible.
#include <iostream>
int main() { int number;
std::cout<<"Enter a number: "; std::cin >>number; if (number<0) { number = -number; } else { number = number; } std::cout<<"Its absolute value is: "<<number<<std::endl; return 0; }
Jeking
Too bad the text was incomplete.
#include <iostream>
int main() { int number;
std::cout<<"Enter a number: "; std::cin >>number; if (number<0) { number = -number; } else { number = number; } std::cout<<"Its absolute value is: "<<number<<std::endl; return 0; }