for example if the user inputs 100 the reverse shows 1, becuase with 001 the leading zeros are unecessary.
I finally did it a complicated way and was wondering if there is an easier way to get the user inputed number into the array, and prefferably into an int array not a char.
heres my code any help is greatly appreciated...
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- void reverse(char input[]){
- int c=0;
- for (int x=0; input[x]!='\0' ; x++)
- c++;
- while (true){
- if (input[c-1] !='0'){
- for(c; c >= 0; c--)
- cout << input[c-1];
- cout << endl;
- break;
- }
- else
- c--;
- }
- }
- int main(void)
- {
- char input[256];
- cout << "Please enter a postive integer: ";
- cin.getline (input,256);
- reverse (input);
- return 0;
- }
Rod