C++ gurus and learners, we program ourselves :P all work is CC licensed

Monday, November 18

Reverse any Integer without strings

It seems now are a stronger community to write generalized programs for FAST NU as well :)
I am posting a program below which reverses any number with just 1 while loop.
See if it works :P
PS please if you copy this or get inspired from this post for your blog then mention us in the post that will be a great gesture than just being douche 3:)
//Code by Umar Farooq
/**
 * follow us at http://CppQA.blogspot.com
 * 
**/
#include <iostream>
using namespace std;

int main() {
 int number = 12345678;
 cout<<"Reverse of number "<<number<<" is ";
 while(number)
 {
  cout<<number%10;
  number/=10;
 }
 
 return 0;
}

6 comments :

  1. i have a working example for you at http://ideone.com/Gfurju #CppQA #blogspot

    ReplyDelete
  2. with the increased number of posts i thing we need a redesign :P

    ReplyDelete
  3. it's so simple and easy........thanks sir

    ReplyDelete
  4. A Big Salute Sir ,,,, ,cuz I have been doing it with another logic ,,,, nd it was just limited to three or digits ,,,, (y)

    ReplyDelete
  5. @Mahin Malik has a great innovation of converting it to a palindrome program. who can do it?
    post a reply here or on facebook :)

    ReplyDelete