C Program to Check if Given Number is Palindrome or Not

//WAP TO CHECK IF GIVEN NO IS PALINDROME OR NOT

#include <stdio.h>
int main()
{
	long int n, ans = 0;
	int digit;

	printf("Enter the number :--> ");
	scanf("%ld", &n);

	long int original = n;
	while(n != 0)               //we reverse the number
	{
		int digit = n % 10;   //to find the last digit of the number
		ans = ans*10 + digit;
		n = n / 10;
	}

	if(ans == original)         //check the reverse number with original to find palindrome
	{
		printf("Number %d is a Palindrome", original);
	}
	else
	{
		printf("Number %d is not a Palindrome", original);
	}

	return 0;
}

<< Previous | Next >>


  • C++ Program to Check if Given Number is Palindrome or Not
  • Java Program to Check if Given Number is Palindrome or Not
  • Python Program to Check if Given Number is Palindrome or Not