Untitled

Exercitiul 10, de la exercitii recapitulative, laboratorul 2.
mail@pastecode.io avatar
unknown
plain_text
2 years ago
697 B
1
Indexable
Never
#include <iostream>
using namspace std;

bool numarPrim(int n);
int mirror(int n);
void ex_2_1_10();


int main() {

ex_2_1_10();
return 0;

}



bool numarPrim(int numar) {

	int divisor = 2;
	while (divisor <= numar / 2) {
		if (numar % divisor == 0) {
			return false;
		}
		divisor = divisor + 1;
	}
	return true;
}


int mirror(int num) {
	int numFinal = 0;
	while (num != 0) {
		numFinal = numFinal * 10 + num % 10;
		num = num / 10;
	}
	return numFinal;
}


void ex_2_1_10() {
	int n = 1000;
	while ((1000 <= n) && (n <= 9999)) {
		if ((numarPrim(n) == true) && (numarPrim(mirror(n))) == true) {
			cout << n << " ";
		}
		n = n + 1;
	}
}