C Program to find palindrome

C Program to find palindrome

A number is said to be Palindrome number if it remains the same after reversing the number. Ex: 121, 34543, 343, 131, 48984 are the palindrome numbers. Through this logic, we create a program to determine whether a given number is a palindrome or not. Once this program is successfully compiled, it will get input from the user and check whether the number is a palindrome or not.


/*
	Check if the Number is Palindrome
	Author 			: 		Krishna Teja G S
	Repository		:		github.com/packetprep/coding-questions
	Website			: 		packetprep.com
*/

#include

int main(){

	int number,lastDigit,originalNumber,reverseNumber=0;

	printf("Enter a positive integer: ");
	scanf("%d",&number);

	originalNumber = number;

	// An integer is a palindrome if the reverse of that number is equal to the original number.
	
	//reverse the number
	while(number!=0){
		//get the last digit
		lastDigit = number % 10;

		reverseNumber = reverseNumber*10 + lastDigit;

		//remove the last digit
		number = number/10;
	}
	

	if(originalNumber == reverseNumber)
		printf("The given number is a Palindrome\n");
	else
		printf("The given number is not a Palindrome \n");

	

}

wipro free mock test
Wipro National Qualifier Test is just a few days away. To help you crack the exam we are sharing a mock test specially designed for Wipro based on all the previous papers.