#include <stdio.h>

int main() {
    int num, reversedNum = 0, remainder, originalNum;

    // Input a number from user
    printf("Enter an integer: ");
    scanf("%d", &num);

    // Store the original number
    originalNum = num;

    // Reverse the number
    while (num != 0) {
        remainder = num % 10;  // Get the last digit
        reversedNum = reversedNum * 10 + remainder;  // Add it to the reversed number
        num /= 10;  // Remove the last digit from the original number
    }

    // Check if the original number is equal to the reversed number
    if (originalNum == reversedNum) {
        printf("%d is a palindrome.\n", originalNum);
    } else {
        printf("%d is not a palindrome.\n", originalNum);
    }

    return 0;
}

Explanation:

  • Input the number: We first take input from the user.
  • Reverse the number: We take the last digit of the number (using % 10), add it to the reversed number, and remove it from the original number (using /= 10).
  • Comparison: If the original number and the reversed number are the same, it is a palindrome; otherwise, it is not.

Leave a Reply

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

Verified by MonsterInsights