C program to check whether a given 5 digit number is palindrome or not

Check for Palindromic number. C program to check whether a given 5 digit number is palindrome or not.

Problem Statement

Write a C program to check if a given 5 digit number is palindrome or not. Take input from the user, check if the given number is a palindromic number and display appropriate message in the end.

A number is said to be a palindromic number if it remains same when reversed. For example 12321 is a palindromic number, where as 12345 is not. You can read more about Palindromic number.

Solution

The program takes input number from the user. Then the digits of the given number are reversed. Reversed number is compared with the original number to check if they are equal. If they are equal, the original number is a palindrome. If they are not equal, then the number is not a palindrome.

The Program

/* C program to check whether a given 5 digit number is palindrome or not
* (c) www.c-program-example.com
*/
#include<stdio.h>
int main() {
int num, rem, i, rev = 0, num1, count = 0;
printf("Enter a five digit number:\n");
scanf("%d", &num);
num1 = num;
// reverse the given number
while(num > 0) {
rem = num % 10;
rev = rem + rev * 10;
num = num / 10;
count++;
}
if(count == 5) {
if(num1 == rev) { // if it's palindrome, reverse & original number will be same
printf("The Given Number %d is Palindrome", num1);
} else {
printf("The Given Number %d is NOT Palindrome",num1);
}
} else {
printf("The given %d number is not a five digit number!",num1);
}
return 0;
}
view raw palindrome.c hosted with ❤ by GitHub

Sample Output

Palindrome number or not

Related Programs

  1. C program to check whether a given string is palindrome or not
  2. Number System

To get regular updates on new C programs, you can Follow @c_program

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to check whether a given string is palindrome or not

Write a C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.Palindrome is a word, sentence, group of characters, or number, that remains same, when reversed.
For example: GADAG, 9009… Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

#include <stdio.h>
#include <conio.h>
#include <string.h>

void main()
{
 char string[25], revString[25]={''};
 int  i,length = 0, flag = 0;

 clrscr();

 fflush(stdin);

 printf("Enter a stringn");
 gets(string);

 for (i=0; string[i] != ''; i++) /*keep going through each */
 {                                 /*character of the string */
  length++;                     /*till its end */
 }

 for (i=length-1; i >= 0 ; i--)
 {
  revString[length-i-1] = string[i];
 }

 /*Compare the input string and its reverse. If both are equal
   then the input string is palindrome. Otherwise it is
   not a palindrome */

 for (i=0; i < length ; i++)
 {
  if (revString[i] == string[i])
   flag = 1;
  else
   flag = 0;
 }

 if (flag == 1)
  printf ("%s is a palindromen", string);
 else
  printf("%s is not a palindromen", string);

}   /*End of main()*/
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com