Imagine you had to write a program that took a four letter word and displayed each letter on a separate line. For instance, a program that takes the word "mice" and displays it;
m
i
c
e
Question is; how would you do this? (hint - arrays are your friend).
Once you answer THAT question, remember that the computer doesn't CARE what WE think the characters mean. To the computer, turning "mice" into;
m
i
c
e
and turning "1234" into
1
2
3
4
is one and the same thing.
Hope this helps get the ol' brain started in the right direction -- let me know if not :)
hint to think about ;)
* escape chars in either printf() or cout functions
I would GIVE you the code to this, however, that would not better you as s programmer. Do as SirCapsAlot said and go to the C++ Tutorial section for control structures and arrays. This should be more than enough to solve this problem, without giving you the answer explicitly.
#include<iostream.h>
void main()
{
int x,r;
cout<<"enter a no";
cin>>x;
while(x>0)
{
a=x%10;//it gets the last charecter
cout<<a;
a=x/10;//it removes the charecter displayed
}
}