This application asks the user for a number, then flips each digit.
To continually extract the final digit and construct the reversed integer, we’ll need a while loop.
#include <stdio.h>
int main() {
int number, reversed = 0;
// Asking user for a number
printf("Enter a number: ");
scanf("%d", &number);
// Reversing the number
while (number != 0) {
int digit = number % 10; // Getting the last digit
reversed = reversed * 10 + digit; // Building the reversed number
number /= 10; // Removing the last digit
}
// Displaying the reversed number
printf("Reversed number: %d\n", reversed);
return 0;
}