C Online Compiler
Example: C Program to Reverse a Given Number using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Reverse a Given Number using While loop #include <stdio.h> // It's the main function of the program int main() { int num, rev = 0, rem, original; // Step-1 Take an input from the User printf("INPUT: "); scanf("%d", &num); // Step-2 Store the input value into the `original` variable original = num; // Step-3 Iterate over the input number using the loop while (num != 0) { rem = num % 10; rev = rev * 10 + rem; num /= 10; } // Step-4 Check if the reminder of original divided by 10 is equal to Zero if (original % 10 == 0) { printf("\nOutput Reversed Number: %d", rev); while (original % 10 == 0) { printf("0"); original /= 10; } } // Step-5 If a reminder of the original is not equal to Zero else { printf("\nOutput Reversed Number: %d", rev); } return 0; }
1234
Output
Clear
ADVERTISEMENTS