C Program to Check If Given Number is Palindrome or Not using While loop

C Program to Check If Given Number is Palindrome or Not using While loop

Write C Program to Check If Given Number is Palindrome or Not using While loop

//WAP to check the given number is palindrome or not

#include<stdio.h>

int main()
{
	long int n, ans = 0;

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

	long int temp = n;

	while(n != 0)
	{
		int remainder = n % 10;  //2  //2  //4
		ans = ans * 10 + remainder;  //2  //22  //224
		n = n / 10;   //42  //4
	}
	if(temp == ans)
	{
		printf("The given number is palindrome");
	}
	else
	{
		printf("The given number is not palindrome");
	}

	return 0;
}

Output:

Run 1:
Enter the number:--> 456
The given number is not palindrome

Run 2:
Enter the number:--> 121
The given number is palindrome