abs in c++
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int x = -5;
long y = -2371041;
int a = abs(x);
long b = abs(y);
cout << "abs(" << x << ") = |" << x << "| = " << a << endl;
cout << "abs(" << y << ") = |" << y << "| = " << b << endl;
}
/* output
abs(-5) = |-5| = 5
abs(-2371041) = |-2371041| = 2371041*/
3.33
3
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int x = -5;
long y = -2371041;
int a = abs(x);
long b = abs(y);
cout << "abs(" << x << ") = |" << x << "| = " << a << endl;
cout << "abs(" << y << ") = |" << y << "| = " << b << endl;
}
Thank you!
3
0
0
0
#include <cmath>
abs(number);
Ex: abs(-10) = |-10| = 10
Thank you!
0
0
3.75
4
[Mathematics] |x| = abs(x) [C++ Programming]
Thank you!
4
0
Are there any code examples left?
New code examples in category C++