Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

c++ very easy part 5 reverse number

  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

Previous Post Next Post