Palindrome Number Program in C

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Palindrome number program in C. Here, we will develop the palindrome number program in C. The palindrome number is based on Reverse of a number. We will also find the palindrome number in the given range.

Palindrome number:- If the Reverse of a number is equal to the same number then the number is called a palindrome number. Example:-
5225 = 5225 So, 5225 is a palindrome number.
123 = 321 So, 123 is not a palindrome number.

Palindrome program in C using while loop

While loop in C is a pre-test loop where the expression is evaluated then only statements are executed. It uses a test expression to control the loop. Before every iteration of the loop, the test expression is evaluated.

#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: 123
123 is not a palindrome number.

Enter the number: 5225
5225 is a palindrome number.

In this program, we take four variables number, remainder, sum, and temp. The variable number stores the input integer value. The variable sum is initialized with 0. Variable temp is used to store the number value temporarily.

Later we used this temp variable to compare the resulting sum. To check number is a palindrome number or not, first we need to reverse the number. The % operator gives the last digit of a number and / operator removes the last digit of the number. Using these operators number is reversed.

Now, it is compared with temporarily stored value using if-else statement. If condition is true then it is palindrome number otherwise it is not palindrome number.

C program to Find palindrome number in a given range

#include<stdio.h>
int main()
{
   long a, b, n, reverse;

   printf("Enter n value: ");
   scanf("%ld",&n);

   for(a=1;a<=n;a++)
   {
     reverse = 0;
     for(b=a; b!=0; b/=10)
     {
       reverse = reverse *10 + b%10;
     }

     if(a==reverse) printf("%ld\t",a);
   }

   return 0;
}

Output:-

Enter n value: 100
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar C Examples

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Comment

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