reversing integers

This is a discussion on reversing integers within the C++ Programming forums, part of the General Programming Boards category; Hey, I was just wondering how you would write a program to input a number (e.g. 1234) and then output ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    30

    reversing integers

    Hey,
    I was just wondering how you would write a program to input a number (e.g. 1234) and then output the number reversed (e.g. 4321)
    Thanks

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    There are many different ways. You can read it in as a string and reverse the string. You could use math (division and modulus) to get each digit and output them in reverse order. You could also search the board and find other options since this is a common question.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    You could also try it yourself first, just in case you feel like learning something
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    29
    If you realy have no idea you can put each digit in a one array cell and then make a loop wich will output the array from the top to the bottom.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-30-2008, 12:35 AM
  4. Replies: 6
    Last Post: 08-04-2003, 11:57 AM
  5. Reversing integers
    By PowderGrrl in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2002, 09:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21