Number N is passed as the input. The program must reverse the number and print the reversed number as the output.
Input Format:
The first line denotes the value of N.
Output Format:
The reversed number.
Boundary Conditions:
1 <= N <= 99999999
Example Input/Output 1:
Input:
1234
Output:
4321
Example Input/Output 2:
Input:
6500
Output:
56
Code:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, rev = 0, remainder;
cin>>n;
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
cout<<rev;
return 0;
}
Post a Comment