C Online Compiler
Example: C Program to Reverse a Given Number using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Reverse a Given Number using For 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 for (int n = num; n != 0; n /= 10) { rem = n % 10; rev = rev * 10 + rem; } // 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); for (int o = original; o % 10 == 0; o /= 10) printf("0"); } // Step-5 If a reminder of the original is not equal to Zero else { printf("\nOutput Reversed Number: %d", rev); } return 0; }
9876
Output
Clear
ADVERTISEMENTS