Advertisement Area

Program #7: To Print the Reverse of a Number using While Loop

C++ Language

#include<iostream.h>
#include<conio.h>
void main()
{
    long rev=0,num,rem,n;
    clrscr();
    cout<<"Enter the Number - ";
    cin>>n;
    num=n;
    while(num!=0)
    {
        rem=num%10;
        num=num/10;
        rev=rev*10+rem;
    }
    cout<<"The Actual Number - "<<n<<endl;
    cout<<"The Reverse Number - "<<rev;
    getch();
}

/*OUTPUT*/
Enter the Number - 1234
The Actual Number - 1234
The Reverse Number - 4321