Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int v[1000000], n;
- int nrprime, nrperf, nrpal;
- void citire()
- {
- cout << "n=";
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cout << "v[" << i << "]=";
- cin >> v[i];
- }
- }
- int ePrim(int x)
- {
- if ((x % 2 == 0 && x != 2 && x != -2) || x == 1)
- return 0;
- for (int d = 3; d * d <= x; d += 2)
- if (x % d == 0)
- return 0;
- return 1;
- }
- int ePerf(int x)
- {
- int s = 1;
- for (int d = 2; d * d <= x; d++)
- {
- if (x % d == 0)
- {
- s += d;
- if (d != (x / d))
- s += x / d;
- }
- }
- if (x == s)
- return 1;
- return 0;
- }
- int ogl(int x)
- {
- int inv = 0;
- do
- {
- inv = inv * 10 + x % 10;
- x /= 10;
- }
- while (x);
- return inv;
- }
- int ePal(int x)
- {
- int inv = ogl(x);
- if (x == inv)
- return 1;
- return 0;
- }
- int sumcif(int x)
- {
- int s = 0;
- do
- {
- s += (x % 10);
- x /= 10;
- }
- while (x);
- s = abs(s);
- return s;
- }
- int main()
- {
- citire();
- for (int i = 0; i < n; i++)
- if (ePrim(v[i]))
- nrprime++;
- cout << "numar numere prime: " << nrprime << endl;
- for (int i = 0; i < n; i++)
- if (ePerf(v[i]))
- nrperf++;
- cout << "numar numere perfecte: " << nrperf << endl;
- cout << "oglindite: " << endl;
- for (int i = 0; i < n; i++)
- cout << "oglinditul lui " << v[i] << " este: " << ogl(v[i]) << endl;
- for (int i = 0; i < n; i++)
- if (ePal(v[i]))
- nrpal++;
- cout << "numar palindroame: " << nrpal << endl;
- cout << "suma cifrelor numerelor: " << endl;
- for (int i = 0; i < n; i++)
- cout << "suma cifrelor lui " << v[i] << " este: " << sumcif(v[i]) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement