Jul 6, 2010 at 1:38pm UTC
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 Jul 6, 2010 at 1:43pm UTC
Jul 6, 2010 at 2:23pm UTC
You might have an easier time with this if you stored the input from the user as a String rather than an int.
Jul 6, 2010 at 3:08pm UTC
Hint:
1234%10==4
1234/10==123
Jul 7, 2010 at 8:04am UTC
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 Jul 7, 2010 at 2:17pm UTC