Reverse

So..keeping it simple..I have to display the reversed numbers of a string.Example:
1 2 3 4 5 6 ....100------------>100 99 98 97......1

1
2
3
4
5
6
7
8
9
10
11
12
      int a,i,inv=0;
    for(i=0;i<=100;i++)
    {
        inv=0;
        a=i;
        while(a)
        {
            inv=inv*10+a%10;
            a=a/10;
        }
        cout<<inv<<" ";
    }

What have I done wrong??
PS:DO NOT USE ANY FUNCTIONS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I'm confused as to why you're using so much code. Why not just count down from 100 instead of counting up and trying to find the inverse. Also, you mention you need to print the reverse of a string, but you aren't using any strings.
1
2
3
for(int i = 100; i >= 0; --i){
cout << i << " ";
}
Last edited on
Topic archived. No new replies allowed.