Palindrome Number Program in C++

Advertisements

Prev Tutorial Next Tutorial

C++ program to Check Number is Palindrome or not

A Palindrome number is a number that remains the same when its digits are reversed. Like 16461, for example: we take 121 and reverse it, after revers it is same as original.

To understand below example, you have must knowledge of following C++ programming topics; For Loop in C++ and Reverse Number Program in C++.

pelindrome number program in c++

Steps to write program

  • Get the value from user.
  • Reverse it.
  • Compare it with the number entered by the user.
  • If both are same then print palindrome
  • Else print not a palindrome.

Palindrome Number Program in C++ using while loop

#include<iostream.h>
#include<conio.h>

void main()
{
int a,no,b,temp=0;
clrscr();
cout<<"Enter any num: ";
cin>>no;
b=no;
while(no>0)
{
a=no%10;
no=no/10;
temp=temp*10+a;
}
if(temp==b)
{
cout<<"Palindrome";
}
else
{
cout<<"Not Palindrome";
}
getch();
}

Output

Enter any num: 143
Not Palindrome
pelindrome number program in c++

Output

Enter any num: 141
Palindrome
pelindrome number program in c++

Palindrome Number Program in C++ using for loop

#include<iostream.h>
#include<conio.h>

void main()
{
int a,no,b,temp=0;
clrscr();
cout<<"Enter any num: ";
cin>>no;
b=no;
for(;no>0;)
{
a=no%10;
no=no/10;
temp=temp*10+a;
}
if(temp==b)
{
cout<<"Palindrome";
}
else
{
cout<<"not Palindrome";
}
getch();
}

Output

Enter any num: 121
Palindrome

Output

Enter any num: 643
Not Palindrome

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements