Sep 22, 2016 at 9:00am
Write your question here.
how to cin 125(one hundred and twenty five),cout 521 (five hundred and twenty one).
Sep 22, 2016 at 9:16am
@SakurasouBusters: I think the OP may want to know how to reverse any given integer. If the program only printed reversed 125, it'd pretty useless.
@ll1234: To reverse an Integer, there are several ways to do it.
Easiest I found is simply turn it into a String or array of char and then reverse the order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <string>
#include <iostream>
int main()
{
std::string input;
std::cout << "Enter a number: ";
std::cin >> input;
for( int i = input.size() - 1 ; i >= 0 ; i-- )
{
std::cout << input[i];
}
}
|
Last edited on Sep 22, 2016 at 9:18am