Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

algorithm of palindrome

0 votes
asked May 6, 2020 by M Yogendra Sai (120 points)

3 Answers

0 votes
answered May 7, 2020 by Afloarei Ioana (290 points)
edited May 8, 2020 by Afloarei Ioana
//Hi, this is c++

#include <iostream>

using namespace std;
long u, n, r, aux;
int main()
{
    cin>>n;
    aux=n;
    r=0;
    do{
        u=aux%10;
        r=r*10+u;
    }while(aux>0);
    if(n==r){
        cout<<"palindrom"<<endl;
    }
    else
     cout<<"no palindrom";

    return 0;
}
commented May 8, 2020 by Afloarei Ioana (290 points)
is it correct?
0 votes
answered May 7, 2020 by Afloarei Ioana (290 points)
//Hi, this is c++

#include <iostream>

using namespace std;
long u, n, r, aux;
int main()
{
    cin>>n;
    aux=n;
    r=0;
    do{
        u=aux%10;
        r=r*10+u;
    }while(aux>0);
    if(n==r){
        cout<<"palindrom"<<endl;
    }
    else
     cout<<"no palidrom";

    return 0;
}
0 votes
answered May 13, 2020 by MatthiasEbert (140 points)
cout << "Is your number a palindrome? " << endl;
    cout << "---------------------------- " << endl;
    
    /// INPUT
        number = -1;
        cout << "Input a positive number: ";
        cin >> number;
        cout << "number= " << number << endl;

    
    if(number <= 0)
    {
        cout << "not allowed" << endl;
        return 1;
    }

    /// CALCULATION
    for ( input = number ; input > 0 ; input /= 10)  // cut the last digit from input from right (last out)
    {
        output=output*10 + input%10;                 // shift output one digit left and put that cutted digit in (first in)
        
        cout << "input=" << input <<  " output=" << output << endl;  //
    }
    
    /// OUTPUT
    if(output == number)
    {
        cout<<"palindrom";
    }
    else
    {
        cout<<"no palindrom";
    }
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...