/****************************************************************************** * This program compute absolute values. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ #include #include #include using namespace std; int main(int argc, char **argv) { int x = 5; cout << fmt::format("|{0:d}| = {1:d}", x, (x < 0 ? -x : x)) << endl; x = -3; cout << fmt::format("|{0:d}| = {1:d}", x, (x < 0 ? -x : x)) << endl; x = 0; cout << fmt::format("|{0:d}| = {1:d}", x, (x < 0 ? -x : x)) << endl; double y = 3.14; cout << fmt::format("|{0:f}| = {1:f}", y, (y < 0 ? -y : y)) << endl; y = -1.2; cout << fmt::format("|{0:f}| = {1:f}", y, (y < 0 ? -y : y)) << endl; y = 0.0; cout << fmt::format("|{0:f}| = {1:f}", y, (y < 0 ? -y : y)) << endl; return 0; }