Thread: Reverse of an integer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    maybe this will work.
    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    main()
    {
          int number,a,a1,b,b1;
          cout<<"Enter a three digit number"<<endl;
          cin>>number;
          //Let the number be 123
          a=number/100;//1
          a1=number%100;//23
          b=a1/10;//2
          b1=a1%10;//3
          cout<<"The reverse of the entered number is "<<b1<<b<<a;
          getch();
          return 0;
          
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Saimadhav View Post
    maybe this will work.
    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    main()
    {
          int number,a,a1,b,b1;
          cout<<"Enter a three digit number"<<endl;
          cin>>number;
          //Let the number be 123
          a=number/100;//1
          a1=number%100;//23
          b=a1/10;//2
          b1=a1%10;//3
          cout<<"The reverse of the entered number is "<<b1<<b<<a;
          getch();
          return 0;
          
    }
    And of course that will work for 3, 4, 6, 10 digit numbers?

    And it's not a separate function.

    Freddy: There is a much simpler way to solve the problem - you don't need to count digits, and you don't need to have more than one variable besides the original number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. gethostbyaddr() reverse lookups failing (???)
    By Uncle Rico in forum C Programming
    Replies: 9
    Last Post: 08-19-2005, 09:22 AM