Saturday, March 12, 2016

Program to check Palindrome number.

Palindrome number

A palindrome number is a number that reads the same forwards and backward. For example, 121, 1331, and 8888 are all palindrome numbers because their digits are the same when reversed.  

Definition: A number that does not change when its digits are reversed. 

Examples: 121, 545, 16461. 

How to check ? To determine if a number is a palindrome, reverse its digits and see if the reversed number is identical to the original. 

C program to check Palindrome number

#include <stdio.h>
#include<string.h>
int main ()
{
 char number[10], reverse[10];
 
 puts("Enter your number:");
 gets(number);
 
 strcpy(reverse, number);
 strrev(number);
 
 printf("Your original number is :%s\n",number);
 printf("Reverse number is: %s\n", reverse);
 
 if(strcmp (number,reverse) == 0 )
  printf("Its Palindrome");
 else
  printf("Not a Palindrome number");
 return 0;
}

Output of program

Enter your number:
121
Your original number is :121
Reverse number is: 121
Its Palindrome



No comments:

Post a Comment