Thread: reversing integers

  1. #1
    Registered User
    Join Date
    Mar 2006

    reversing integers

    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)

  2. #2
    Registered User
    Join Date
    Jan 2005
    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
    The edge of the known universe
    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.

  4. #4
    Registered User
    Join Date
    Jun 2006
    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-29-2008, 11:35 PM
  4. Replies: 6
    Last Post: 08-04-2003, 10:57 AM
  5. Reversing integers
    By PowderGrrl in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2002, 09:01 AM