C++:Reverse a number
Printer-friendly version
Upon request, i am posting a small program which would reverse a number.For an example we have:
Input 12345
Output 54321
Note:Please use long as data type else this program will no work for digits greater than four.
Here goes the program.
#include<iostream.h> void main() { cout<<"\t\t||Jai Saraswati||\n\n"; long num,rem,newn=0; cout<<"Enter the Number:\t"; cin>>num; while(num!=0) { rem=num%10; newn=rem+newn*10; num=num/10; } cout<<"Reverse Number is:\t"; cout<<newn; } [/C++]
Similar
- Kopete Google Talk Invisible
- Python vs PHP (webdev)
- Getting Started with C++
- Portable Graphical Programming For Linux and Windows in C++
- C++: Ditch Turbo C++ use Relo !
- Generating Serial Page Numbers in PHP [Pager]
- Adding your META tags on to a drupal page
- Remove your site titles from content pages in Drupal
- PHP: Receiving Function Arguments without declaring any parameters in prototype!
- Extracting Data from a file using cut and grep
Comments
Another option also possible
I don't know much of C++, but we had to do this exercise in VB 6 too, so I used to convert LONG to String and then reverse the string because that was easier in VB.
Nilesh Govindrajan
Site & Server Administrator
iTech7
One thing i like most about
One thing i like most about programing is that unlike other subjects users are not bounded to do a task within the lines. We focus more on result rather than the way of doing it. So its all your wish how to solve a question...
Ontopic I have not tried but i don't think it will be user friendly to convert data types in C++.