Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int SumaCifre(int nr)
- {
- int cifra, sCifre(0);
- while(nr)
- {
- cifra = nr % 10;
- sCifre += cifra;
- nr /= 10;
- }
- return sCifre;
- }
- int NrCifre(int nr)
- {
- int contorCifre(0);
- while(nr)
- {
- contorCifre++;
- nr /= 10;
- }
- return contorCifre;
- }
- int Invers(int nr)
- {
- int inv(0), cifra;
- while(nr)
- {
- cifra = nr % 10;
- inv = inv * 10 + cifra;
- nr /= 10;
- }
- return inv;
- }
- int Palindrom(int nr)
- {
- int inv(0), cifra, aux;
- aux = nr;
- while(aux)
- {
- cifra = aux % 10;
- inv = inv * 10 + cifra;
- aux /= 10;
- }
- if(inv == nr)
- return 1;
- else return 0;
- }
- int main()
- {
- int a;
- cin >> a;
- cout << "Suma cifrelor este: " << SumaCifre(a) << endl;
- cout << "Numarul de cifre: " << NrCifre(a) << endl;
- cout << "Inversul numarului este: " << Invers(a) << endl;
- if(Palindrom(a))
- cout << "Numarul introdus este palindrom.";
- else cout << "Numarul introdus nu este palindrom.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement