Computer Science, asked by mitali098, 1 year ago

Write a C++ program of palindrome

Answers

Answered by jigarraas
1
o check for palindrome i.e., whether entered number is palindrome or not in C++ programming, you have to first ask from the user to enter a number. Now to check whether the entered number is a palindrome number (if reverse of the number is equal to its original) or not a palindrome number (if reverse of the number is not equal to its original), you have to first reverse the number and check whether reverse is equal to original or not. If it is equal then the number is palindrome, otherwise not palindrome number as shown here in the following program.

C++ Programming Code to Check Palindrome or Not

Following C++ program ask to the user to enter a number to reverse it, then check whether reverse is equal to its original or not, if it is equal then it will be palindrome else it will be not be palindrome:

/* C++ Program - Check Palindrome or Not */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int num, rem, orig, rev=0; cout<<"Enter a number : "; cin>>num; orig=num; while(num!=0) { rem=num%10; rev=rev*10 + rem; num=num/10; } if(rev==orig) // check if original number is equal to its reverse { cout<<"Palindrome"; } else { cout<<"Not Palindrome"; } getch(); }

When the above C++ program is compile and executed, it will produce the following result. Above C++ Programming Example Output (palindrome):



Above C++ Programming Example Output (not palindrome):



Answered by sushiladevi4418
0

Answer:

Write a C++ program of palindrome

Explanation:

#include <iostream>

using namespace std;

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;

}

Output:-

Enter a positive number: 121

The reverse of the number is: 121

The number is a palindrome.

Similar questions