Thread: Reversing integers

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