How do we reverse a number with leading zeroes in number ? For ex: If input is 004, output should be 400.
I wrote below program but it works only when n
A recursive approach, but easily converted to a loop...
#include int f(int value = 1) { char c; return (std::cin.get(c) && isdigit(c)) ? (c - '0') * value + f(10 * value) : 0; } int main() { std::cout << f() << '\n'; }