Explanation: We have included the library for I/O.
We define num for the user’s input, reversed for the reversed integer, and remaining for the final digit.
We prompt the user to enter and read an integer.
We use a while loop that continues until num reaches zero.
Inside the loop, we retrieve the last digit and construct the inverted number.
Following the loop, we publish the reversed number.

#include <stdio.h>

int main() {
    int num, reversed = 0, remainder;
    printf("Enter an integer: ");
    scanf("%d", &num);

    while (num != 0) {
        remainder = num % 10; // Get the last digit.
        reversed = reversed * 10 + remainder; // Build the reversed number.
        num /= 10; // Remove the last digit.
    }

    printf("Reversed Number: %d\n", reversed); // Output the reversed number.
    return 0;
}

Leave a Reply

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

Verified by MonsterInsights