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

INFEED

C – VERY-EASY – PART005-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 <stdio.h>
int main() {
    int n, rev = 0, remainder;
    scanf("%d", &n);
    while (n != 0) {
        remainder = n % 10;
        rev = rev * 10 + remainder;
        n /= 10;
    }
    printf("%d", rev);
    return 0;
}

Post a Comment

Previous Post Next Post