C Program To Check Whether A Number Is Palindrome or Not
C Program To Check Whether A Number Is Palindrome or Not
PalindromeorNot
This program reverses an integer (entered by the user) using while loop. Then the if...else
statement is used to check whether the number entered is equal to the reversed number.
Tounderstandthisexample,youshouldhavetheknowledgeoffollowingCprogrammingtopics:
CProgrammingOperators
Cif,if...elseandNestedif...elseStatement
Cprogrammingwhileanddo...whileLoop
Anintegerisapalindromeifthereverseofthatnumberisequaltotheoriginalnumber.
Example:ProgramtoCheckPalindrome
#include<stdio.h>
intmain()
{
intn,reversedInteger=0,remainder,originalInteger;
printf("Enteraninteger:");
scanf("%d",&n);
originalInteger=n;
//reversedintegerisstoredinvariable
while(n!=0)
{
remainder=n%10;
reversedInteger=reversedInteger*10+remainder;
n/=10;
}
//palindromeiforignalIntegerandreversedIntegerisequal
if(originalInteger==reversedInteger)
printf("%disapalindrome.",originalInteger);
else
printf("%disnotapalindrome.",originalInteger);
return0;
}
Output
Enteraninteger:1001
1001isapalindrome.
Checkouttheserelatedexamples:
CProgramtoCountNumberofDigitsofanInteger
CProgramtoPrintanIntegerEnteredbytheUser
CProgramtoComputeQuotientandRemainder
FlyingtoBangalore?
FreeJEEStudyMaterials
InstantGrammarChecker
CProgramtoCheck
ArmstrongNumber
Ad airasia.com
Ad EtoosIndia.com
Ad Grammarly
programiz.com
CProgramtoMakea
SimpleCalculatorUsing...
CProgramtoDisplay
FibonacciSequence
CProgrammingCodeTo
CreatePyramidand...
CProgramtoReversea
Number
programiz.com
programiz.com
programiz.com
programiz.com
RelatedExamples
C Program to Check Whether a Number is Even or Odd
C Program to Check Whether a Character is Vowel or Consonant
C Program to Find the Largest Number Among Three Numbers
C program to Find all Roots of a Quadratic equation
C Program to Check Leap Year
CopyrightbyProgramiz|Allrightsreserved|PrivacyPolicy
Join