Header Ads Widget

Ticker

6/recent/ticker-posts

Palindrome program in C++ Notes+Coding by Digitalise Data

 

Palindrome program in C++ Notes+Coding by Digitalise Data

Palindrome program in C++

palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers.

Palindrome number algorithm

  • Get the number from user
  • Hold the number in temporary variable
  • Reverse the number
  • Compare the temporary number with reversed number
  • If both numbers are same, print palindrome number
  • Else print not palindrome number

Let's see the palindrome program in C++. In this program, we will get an input from the user and check whether number is palindrome or not.

  1. #include <iostream.h>
  2. #include <conio.h>   
  3. int main()  
  4. {  
  5.   int n,r,sum=0,temp;    
  6.   cout<<"Enter the Number=";    
  7.   cin>>n;    
  8.  temp=n;    
  9.  while(n>0)    
  10. {    
  11.  r=n%10;    
  12.  sum=(sum*10)+r;    
  13.  n=n/10;    
  14. }    
  15. if(temp==sum)    
  16. cout<<"Number is Palindrome.";    
  17. else    
  18. cout<<"Number is not Palindrome.";   
  19.   return 0;  
  20. }  

Output:

Enter the Number=121   
 Number is Palindrome.	
Enter the number=113  
Number is not Palindrome.

Post a Comment

0 Comments