Home » Palindrome program in C using while loop

Palindrome program in C using while loop

Learn about Palindrome program in C using while loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

Palindrome program in C using while loop

The below C program checks the number entered by the user is a Palindrome or not. While loop is used in the below program to check the palindrome.

Program:

#include<stdio.h>
int main()
{
     int number, remainder, sum=0 ;
     int temp;

     printf("Enter the number : ");
     scanf("%d", &number);

     temp = number;

     while( number!=0 )
     {
         remainder = number % 10;
         sum = sum*10 + remainder;
         number /= 10;
     }

     if ( sum == temp )
         printf("%d is a palindrome number.\n",temp);
     else
         printf("%d is not a palindrome number.\n",temp);

     return 0;
}

Output:

Enter the number : 141
141 is a palindrome number.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to Find Neon Number in a Given Range
C Program to check Neon Number using for Loop