1. This application asks the user for a number, then flips each digit.
  2. 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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights