Palindrome Number Program in C++

Google 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 Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

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

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders. Difference between path and classpath in Java

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs