👤

Se dau n numere naturale. Sa se verifice daca printre numerele citite exista un palindrom prim,afisand pe ecran un mesaj corespunzator.(cu for)

Răspuns :

#include <iostream>

using namespace std;

int n, x, y, x2, ok, p, d, i, k;

int main ()

{

cin >> n;

k = 1;

for (i = 1; i <= n; i ++) {

cin >> x;

ok = 0;

if (x == 1 || x == 0) ok = 1;

for (d = 2; d <= x/2; d ++) if (x%d == 0) ok = 1;

if (x == 2) ok = 0;

if (ok == 0) {

p = 1;

x2 = x;

y = 0;

while (x2 > 0) {

y = x2%10*p + y;

x2 = x2/10;

p = p*10;

}

if (x == y) {cout << "Exista palindromul prim: " << x << endl; k = 0;}

}

}

if (k == 1) cout << "Nu exista un palindorm prim";

return 0;

}

Vezi imaginea OILOVEYOUO
Vezi imaginea OILOVEYOUO