Reversing integers

This is a discussion on Reversing integers within the C++ Programming forums, part of the General Programming Boards category; I have just started a C++ class. I am totally confused right now. I have an assignment that asks me ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    Question Reversing integers

    I have just started a C++ class. I am totally confused right now. I have an assignment that asks me to reverse integers without using arrays or strings. The program should consist of two loops. The program should look something like this:
    Enter a variable (negative or 0 to quit): 2345
    Your variable reversed is 5432

    How do I get the varable to reverse?
    Help me!

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    This is my ver of your problem

    ----
    ----

    int n,temp,rev;

    cin>>n;

    rev=0;
    while(n>=1)
    {
    temp=n%10;
    temp=temp*10;
    rev=rev*10;
    rev=rev+temp;
    n=n/10;
    }

    r=r/10;
    cout<<"REVERSE : "<<rev;
    ----
    ----

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. reversing integers
    By rachael033 in forum C++ Programming
    Replies: 3
    Last Post: 06-16-2006, 04:58 AM
  5. Replies: 6
    Last Post: 08-04-2003, 11:57 AM

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