reverse positive integer number using loop

closed account (1RLTURfi)
I am a new beginner in c++.I want to write a program that prompts user to input a positive integer number and then output the number with the digits reversed.For example if the input is 12345,the output should be 54321.Must also output 8000 as 0008 and 230 as 032.

this is the program i have written,but it was totally wrong!help me.

#include <iostream>
using namespace std;

int main()
{
int count , num;


cout << "Please enter an integer";
cin >> num;



count = 1; // initialize count
while (count <= 10)
{
cout << count << " ";
count++; // increment count
}


int i;

i = 10;
while (i >= 1)
{
cout << i << " ";
i--; // subtract 1 from i
}

system ("pause");


return 0;
}
Last edited on
You might have an easier time with this if you stored the input from the user as a String rather than an int.
Hint:
1234%10==4
1234/10==123
closed account (1RLTURfi)
I already solve the question now I want to repeat this.how.continuous many times.not reverse once only.repetition.help me






#include <iostream>
using namespace std;

int main()

{

int num, rev;

cout <<"Please enter an integer: ";
cin >> num;

cout <<"Your reversed number is ";

while(num>0)

{

rev = num%10;
num=num/10;


cout << rev;



}

cout <<"\n";



system ("pause");





return 0;
}
Last edited on
Topic archived. No new replies allowed.