Adsense 728 * 15

Search

Custom Search

C, C++ Program to check number is Palindrome or not

Write C, C++ Program to check number is palindrome or not. To check whether number is palindrome or not, just reverse the number and check whether original and reverse number is same or not.

If both original and reverse number is same then the number is Palindrome.

As per Wikipedia, A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.

452 - Not a palindrome number. Reverse of that number is 254.

121 - Palindrome number. Reverse of that number is 121.


Program to check whether string is Palindrome


C++ program to check number is palindrome or not




C++ code for palindrome number.

#include <iostream.h>


int main()
{ 
   
     int n, num, digit, rev = 0;
     cout << "Enter a positive number: ";
     cin >> num;

     n = num;

     do
     {
         digit = num%10;
         rev = (rev*10) + digit;
         num = num/10;
     }while (num!=0);

     cout << " The reverse of the number is: " << rev << endl;
     if (n = = rev)
       cout << " The number is a palindrome";
     else
       cout << " The number is not a palindrome";
                  
    return 0;
}    

C Code to check number is Palindrome or not



#include <stdio.h>

int main()
{ 
   
     int n, num, digit, rev = 0;
     printf("Enter a positive number: ");
     scanf("%d",&num);

     n = num;

     do
     {
         digit = num%10;
         rev = (rev*10) + digit;
         num = num/10;
     }while (num!=0);

     printf(" The reverse of the number is: %d",rev);
     
     if (n == rev)
       printf(" The number is a palindrome");
     else
       printf(" The number is not a palindrome");
  
  return 0;                
    
}    


Output -

Enter a positive number:  121

The number is a palindrome

Program to check entered character is vowel.

No comments:

Post a Comment