Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Palindrome Program in C

by suresh

Write a Program for Palindrome in C Programming to Check Whether the Number is Palindrome or Not. For this Palindrome in C program, we use while Loop, For Loop, Functions, and Recursion. We also show you how to write a C Program for Palindrome Numbers from 1 to 1000.

Palindrome in C: Any number could be Palindrome in C if it remained the same when we reversed it. For example, 191 is a palindrome number because this number remains the same after reversing the number.

The following steps are the standard procedure to check for the Palindrome Number in C Programming.

  1. Please enter any number to check for Palindrome in C.
  2. Reverse a given number
  3. Compare the original given value with the reverse value.
  4. If they matched correctly, then it is a Palindrome number. Otherwise, it is not a Palindrome number in C programming.

Palindrome in C using While Loop

This C program for Palindrome allows the user to enter any positive integer and. Next, this C program checks whether the given number is Palindrome Number or Not using the While Loop

/* Palindrome Program in C using While Loop */
#include <stdio.h>

int main()
{
   int Number, Temp, Reminder, Reverse = 0;
 
   printf("\nPlease Enter any number to Check for Palindrome\n");
   scanf("%d", &Number);
  
   //Helps to prevent altering the original value
   Temp = Number;

   while ( Temp > 0)
   {
      Reminder = Temp %10;
      Reverse = Reverse *10+ Reminder;
       Temp = Temp /10;
   }
 
   printf("Reverse of entered number is = %d\n", Reverse);

   if ( Number == Reverse )
      printf("\n%d is Palindrome Number.\n", Number);

   else
      printf("%d is not the Palindrome Number.\n", Number);
 
   return 0;
}
Palindrome Program in C Using While

In this C palindrome program, We assign the original value to the Temp variable. It helps to protect our original value and perform the manipulation on the Temp variable.

Next, the While Loop Condition will make sure that, the given number is greater than 0

User Entered value in this C palindrome number program : Number = 1331 and Reverse = 0

Temp = Number

It means, Temp = 1331

First Iteration

Reminder = Temp %10
Reminder = 1331%10 = 1

Reverse = Reverse *10 + Reminder
Reverse = 0 * 10 + 1 = 0 + 1 => 1

Temp = Temp /10 => 1331 /10
Temp = 133

Second Iteration

From the first Iteration of palindrome program in c, the values of both Temp and Reverse has changed as Temp = 133 and Reverse = 1

Reminder = Temp % 10 = 133 % 10 = 3

Reverse = 1 * 10 + 3 = 10 + 3 => 13

Temp = Temp /10 = 133 /10 => 13

Third Iteration: Temp = 13 and Reverse = 13

Reminder = Temp %10 = 13%10 = 3

Reverse = 13 * 10 + 3
Reverse = 130 + 3 => 133

Temp = 13/10 = 1

Fourth Iteration: Temp = 1 and Reverse = 133

Reminder = 1 %10 = 1

Reverse = 133 * 10 + 1
Reverse = 1330 + 1 = 1331

Temp = 1/10
Temp = 0

Here, Number = 0. It means, the while loop fails

if ( Number == Reverse ) – condition will check whether the user enter number is exactly equal to the Reverse number or not. If condition is True, it is a Palindrome Number. Otherwise, it’s not a Palindrome number.

if ( Number == Reverse ) means if(1331 ==1331) – TRUE, Palindrome

C Palindrome using For Loop

This program for palindrome in c check whether a given number is Palindrome Number or Not using the For Loop

/* Program for Palindrome in C using For Loop */
#include <stdio.h>

int main()
{
  int Number, Temp, Reminder, Reverse = 0;
 
  printf("\nPlease Enter any number to Check for Palindrome\n");
  scanf("%d", &Number);
   
  for(Temp = Number; Temp > 0; Temp =  Temp /10 )
  {
     Reminder = Temp %10;
     Reverse = Reverse *10+ Reminder;
  }
 
  printf("Reverse of entered number is = %d\n", Reverse);

  if ( Number == Reverse )
     printf("\n%d is Palindrome Number.\n", Number);

  else
     printf("%d is not the Palindrome Number.\n", Number);
 
  return 0;
}
Palindrome in C using For Loop

We replaced the While loop of first palindrome example with For Loop.

Palindrome Number using Functions

This program for Palindrome in c check a number is Palindrome Number or Not using Functions concept.

/* Program for Palindrome in C using Functions */
#include <stdio.h>

int Reverse_Integer (int)

int main()
{
  int Number, Reverse = 0;
 
  printf("\nPlease Enter any number to Check for Palindrome\n");
  scanf("%d", & Number);
 
  Reverse = Reverse_Integer (Number)

  printf("Reverse of entered number is = %d\n", Reverse);

  if ( Number == Reverse )
     printf("\n%d is Palindrome Number.\n", Number);
  else
     printf("%d is not the Palindrome Number.\n", Number);
 
  return 0;
}

int Reverse_Integer (int Number)
{
  int Reminder, Reverse = 0;

  for(; Number > 0; Number =  Number /10 )
   {
     Reminder = Number %10;
     Reverse = Reverse * 10 + Reminder;
   }

  return Reverse;
}
Palindrome in C Using Functions

When the C compiler reaches to Reverse_Integer (Number) line in the main() program then the C compiler jumps to below function:

int Reverse_Integer (int Number)

The last line of this palindrome program ends with a return Reverse statement.

Palindrome program using Recursion

This C program checks the number is Palindrome Number using the Recursive Functions concept in C Programming.

/* Program for Palindrome in C using Recursion */
#include <stdio.h>

int Reverse_Integer (int)

int main()
{
  int Number, Reverse = 0;
 
  printf("\nPlease Enter any number to Check for Palindrome\n");
  scanf("%d", & Number);
 
  Reverse = Reverse_Integer (Number)

  printf("Reverse of entered number is = %d\n", Reverse);

  if ( Number == Reverse )
     printf("\n%d is Palindrome Number.\n", Number);
  else
     printf("%d is not the Palindrome Number.\n", Number);
 
  return 0;
}

int Reverse_Integer (int Number)
{
  static Reminder, Reverse = 0;
 
  if (Number > 0)
   {
     Reminder = Number %10;
     Reverse = Reverse *10+ Reminder;
     Reverse_Integer (Number /10);
     return Reverse;
   }
  else
     return 0;
}
Palindrome in C Using Recursion

Within this Palindrome in c program, when the compiler reaches to Reverse_Integer (Number) line in the main() program then the compiler will immediately jump to below function:

int Reverse_Integer (int Number)

In this function, Reverse_Integer (Number /10) statement will help to call the function Recursively with the updated value. If you miss this statement in the palindrome program, after completing the first line, it will terminate. For example, Number = 1331 then the output will be 1

Let’s see the If condition in this C program

if (Number > 0) – checks the number is greater than 0 or not. For Recursive functions, it is essential to place a condition before using the function recursively. Otherwise, the program will end up in infinite executions (Same like Infinite Loop).

C Program for Palindrome Numbers between 1 and 1000

This palindrome program allows you to enter a minimum and maximum values. This program finds the Palindrome Number between the Minimum and Maximum values.

#include<stdio.h>

int main()
{
  int Number,Reminder,Reverse,Temp;
  int Minimum,Maximum;

  printf("\nPlease Enter the Minimum & Maximum Values\n");
  scanf("%d %d",&Minimum, &Maximum);

  printf("Palindrome numbers Between %d and %d are:\n",Minimum, Maximum);

  for(Number=Minimum;Number<=Maximum;Number++)
   {
     Temp=Number;
     Reverse =0;
     while (Temp > 0)
      {
        Reminder =  Temp %10;
        Reverse = Reverse *10+ Reminder;
        Temp =  Temp /10;
      }
   if(Number==Reverse)
      printf("%d ",Number);
   }
 return 0;
}
Palindrome Numbers in C 2

This For Loop restrict the compiler to repeat between Minimum & Maximum Variables. I mean, iteration starts at Minimum and ends at the Maximum variable.

for (Number=Minimum; Number<=Maximum; Number++)

if(Number==Reverse) -– condition will checks the iteration number is accurately equal to the Reverse number. If it’s true, it is a Palindrome else the given number is not Palindrome number.

Placed Under: C Programs

  • C Hello World
  • C Add Two numbers
  • C Armstrong Number Program
  • C Convert Celsius to Fahrenheit
  • C Convert Decimal to Binary
  • C Convert Decimal to Octal
  • C Convert CM to Meter and KM
  • C Convert KM to M, CM & MM
  • C Convert Fahrenheit to Celsius
  • C Compound Interest Program
  • C Count Digits in a Number
  • C Count Notes in an Amount
  • C Cube of a Number
  • C Electricity Bill Program
  • C Factors of a Number Program
  • C Factorial of a Number Program
  • C GCD of Two Numbers
  • C Generic Root of a Number
  • C Gross Salary of an Employee
  • C Largest of Two Numbers
  • C Largest of Three numbers
  • C Last Digit Of a Number
  • C LCM of Two Numbers
  • C Leap Year program
  • C Multiplication Table program
  • C Natural Numbers from 1 to N
  • C Natural Numbers in reverse
  • C NCR Factorial of a Number
  • C Number is Divisible by 5 and 11
  • C Palindrome Program
  • C Palindrome String program
  • C Perfect Number Program
  • C Profit or Loss Program
  • C Print 1 to 100
  • C Print Prime Numbers 1 to 100
  • C Prime Number program
  • C Prime Factors of a Number
  • C Prime, Armstrong or Perfect
  • C Positive or Negative program
  • C Print Odd Numbers 1 to N
  • C Print Even Numbers 1 to N
  • C Print Integer, Char & Float
  • C Power of a Number program
  • C Product of Digits in a Number
  • C Roots of a Quadratic Equation
  • C Reverse a Number
  • C Simple Calculator Program
  • C Simple Interest
  • C Square of a Number
  • C Square Root of a Number
  • C Standard Deviation program
  • C Strong Number Program
  • C Student Grade program
  • C Sum of Odd Numbers program
  • C Sum of Even Nums program
  • C Sum of Even and Odd Nums
  • C Swap First & Last digit of Num
  • C Sum of First & Last digit Num
  • C Sum of Digits of a Number
  • C Sum of N Numbers Program
  • C Sum and Average of n Number
  • C Swap 2 Numbers
  • C Total, Avg & % of Five Subjects
  • C Quick Sort
  • C Selection Sort
  • C Insertion Sort
  • C Bubble Sort
  • C Fibonacci Series Program
  • C Nth Fibonacci number
  • C Sum of AP Series
  • C Sum of GP Series
  • C Sum of series 1³+2³+3³+….+n³
  • C Sum of series 1²+2²+3²+….+n²
  • C ASCII value of String chars
  • C Print Characters in a String
  • C Compare Two Strings
  • C Concatenate Two Strings
  • C Copy String
  • C String length program
  • C Convert String to Lowercase
  • C First Occurrence of string char
  • C First Occur of String Word
  • C Count Occur of string Char
  • C Count Alphabets, Digits & Special Chars
  • C Count Vowels & Consonants
  • C string remove all Occ of char
  • C remove 1st Occ of char in string
  • C remove last Occ char in string
  • C replace All Occ of char in string
  • C Replace last Occ of String Char
  • C Replace 1st occ char in string
  • C Reverse words Order in string
  • C Reverse a String
  • C Toggle Case of all char in string
  • C Array Arithmetic Operations
  • C Matrix Arithmetic Operations
  • C Count Frequency of array item
  • C Count Duplicate Array items
  • C Count +ve & -Ve Array items
  • C Count Even & Odd Array items
  • C Copy an Array to another
  • C Delete Duplicate Array items
  • C Delete an Element in an Array
  • C insert an Element in an Array
  • C 2nd largest Number in an Array
  • C Find Largest Array Number
  • C Find Smallest Array Number
  • C Largest & Smallest Array item
  • C Merge Two Arrays
  • C Print Unique Array Elements
  • C Print Arrayy Elements
  • C Print Negative Array Numbers
  • C Print Positive Array Numbers
  • C Put +ve & -Ve in 2 Arrays
  • C Put Even & Odd in 2 Arrays
  • C Program to Reverse an Array
  • C Search an Element in an Array
  • C Sum of array even, odd nums
  • C Sort Array in Ascending Order
  • C Sort Array in Descending
  • C Swap 2 Arrays without Temp
  • C Sum of all Array Elements
  • C Sum of each Matrix column
  • C sum of each row in a Matrix
  • C Sum of Matrix row & column
  • C Add Two Matrices
  • C Sparse Matrix
  • C Symmetric Matrix
  • C Identity Matrix
  • C Interchange Matrix Diagonals
  • C Check two Matrices Equal
  • C Lower Triangle of a Matrix
  • C Upper Triangle of a Matrix
  • C Sum of Lower Triangle Matrix
  • C Sum of Upper Triangle Matrix
  • C Subtract Two Matrices
  • C Transpose of a Matrix program
  • C Cuboid Volume & Surface Area
  • C Cone Volume & Surface Area
  • C Cube Volume & Surface Area
  • C Volume & Surface of Cylinder
  • C Volume & Surface of Sphere

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy