- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if the value entered is palindrome or not using C language
A palindrome is nothing but any word, number, sentence, or other sequence of characters that reads the same backward as forward.
In this programming, we are trying to enter a number from console, and assign that number to temp variable.
If number is greater than zero, apply the logic given below −
while(n>0){ r=n%10; sum=(sum*10)+r; n=n/10; }
If temp=sum, then the given number is a palindrome. Otherwise, it is not a palindrome.
Example
Following is the C program for verification of a value being palindrome −
#include<stdio.h> #include<conio.h> void main(){ int n, r, sum=0, temp; printf("Enter a number: "); scanf("%d",&n); temp=n; while(n>0){ r=n%10; sum=(sum*10)+r; n=n/10; } if(temp==sum) printf("It is a palindrome number!"); else printf("It is not a palindrome number!"); getch(); }
Output
When the above program is executed, it produces the following result −
12345 It is not a palindrome number
Advertisements