[ create a new paste ] login | about

Link: http://codepad.org/7Sb7dvld    [ raw code | output | fork ]

hmurcia - C++, pasted on Sep 7:
// PALINDROME:  Es un número dado, palíndrome o no?

#include<iostream>
#include<cstring>
using namespace std;

int sumadigit(short numero);
bool numpalindr(short);
void itoa(short, char *, short);

int main ()
{
    int numero;
    cout<<"  °°°°°Programa que Halla la sumatoria de los digitos de un numero entero°°°°°";
    cout<<"\n\n\ningrese el numero para sumar los digitos  -->  ";
    cin>>numero;

    cout<<"\nla suma de los digitos  de  "<<numero<<"   es  " << sumadigit(numero)<<"\n\n";
    cout << "\n\nEl numero anterior ";
    if (!numpalindr(numero))
        cout << "no ";
    cout << "es palindrome.";
    // system("pause");
}

int sumadigit(short num) {
    if (num<10) {
        return num;
    }
    else
        return num%10 + sumadigit(num/10);
}

bool numpalindr( short n ) {
    if (n<10) return true;

    char s[6];
    itoa(n, s, 10);
    short l = strlen(s);
    if (*s != *(s+l-1))
        return false;
    return numpalindr(atoi(s+1)/10);
}


Output:
1
2
In function `numpalindr(short)':
undefined reference to `itoa(short, char*, short)'


Create a new paste based on this one


Comments: