Răspuns :
Răspuns:
Problema 1
#include <iostream>
using namespace std;
int main(){
int x[1000];
int n;
int i;
int a;
int k = 0;
cout << "n=";
cin >> n;
for (i = 0;i < n; i++){
cout << "Numarul " << i+1 << " : ";
cin >> x[i];
}
cout << "a=";
cin >> a;
for (i = 0;i < n; i++){
if (x[i] == a){
k++;
}
}
if (k > 1) {
cout << "Numarul " << a << " se intalneste in sirul introdus de " << k << " ori\n";
} else if (k == 1) {
cout << "Numarul " << a << " se intalneste in sirul introdus o data\n";
} else {
cout << "Numarul " << a << " nu se intalneste in sirul introdus \n";
}
return 0;
}
Problema 2
#include <iostream>
using namespace std;
int main(){
int n;
cout << "n=";
cin >> n;
cout << "Numerele pana la " << n << " cu 3 divizor proprii:\n";
for (int i = 1;i <= n; i++){
int k = 0;
for (int d = 2;d < i; d++){
if (i % d == 0){
k++;
}
}
if (k == 3){
cout << i << ' ';
}
}
cout << endl;
return 0;
}
Explicație: