Program to reverse a number.

Definition:- Reversing the number means changing the places of the digits, like if the number is 3456 then the output will be 6543.

Program:-

#include <iostream.h>
#include<conio.h>
void main()
{   clrscr();
    int n, reversedNumber = 0, remainder;
    cout<<"\n\n";
    cout << "Enter an integer: ";
    cin >> n;

    while(n != 0)
    {
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
    }

    cout << "Reversed Number = " << reversedNumber;
getch();
}

Output:-

Post a Comment

0 Comments