Showing posts with label Example of Palindrome Number. Show all posts
Showing posts with label Example of Palindrome Number. Show all posts

Monday, 2 October 2017

write a program to check palindrome or not in c++

C++ Program to Check Whether a Number is Palindrome or Not

Before this program You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop.


What is Palindrome number?

The number is palindrome if reverse digit equal to original digit its
also known as palindrome.If reverse number is not equal to given number so it is not palindrome number.



Example of Palindrome Number

121,  12321,  34543, This number is palindrome.



Example.C++ Program to reverse an number


#include<iostream>
#include <conio.h>
using namespace std;
int main ( )
 {
  int orgnum,reminder,sum=0,num;
cout<<"Please enter the number";

   cin>>orgnum;
  num=orgnum;
   //this condition is use to check num not = zero. 

    while(num!=0)
{
   reminder=num%10;
   sum = (sum*10) + reminder;
   num = num / 10;
}
   if(sum==orgnum)

cout <<orgnum<<"This number is palindrome";
else
cout <<orgnum<<"This number is not palindrome";


return 0;
getch ();
}
}


Output
--------------------------------------------
Please enter the number    
       ; 
78987           
                           :
78987 this number is palindrome 
--------------------------------------------


In above program ,a positive number enter by the user which value is stored in orgnum variable.



After that,we copied onum into num variable
num=onum;

we using the while loop for unit number num  !  = 0 is false

Inside the while loop , last digit is different  from num by the operation digit = num % 10;. This digit is module and added to the variable sum.

after we check original number is equal to reverse number.then we 
Finally reverse digit is displayed on the monitor



-----------------------------------------------------------------------------------------------
You should have basic programming knowledege
like syntax and variable and if else statement or for loop that is must learn before starting
the program.
The people who want to learn programming language.this website very beneficial for those people.