Răspuns :
Răspuns:
Problema 1:
#include <iostream>
using namespace std;
int main(){
int n;
int k = 0;
cout << "n=";
cin >> n;
for (int i = 8;i <= n; i++){
if (n % i == 0){
k++;
}
}
cout << "Numarul " << n << " are " << k << " divizori proprii mai mari ca 7";
return 0;
}
Problema 2:
#include <iostream>
using namespace std;
int fourgigit(int n){
while (n != 0){
if (n % 10 == 4){
return 1;
}
n /= 10;
}
return 0;
}
int main(){
int n;
cout << "n=";
cin >> n;
int i = 0;
int k = 0;
while (i < n){
int nr;
cin >> nr;
if (fourgigit(nr)) {
k++;
}
i++;
}
cout << k << " numere contin cifra 4.";
return 0;
}
Problema 3:
#include <iostream>
using namespace std;
int main(){
int n;
int k = 1;
cout << "n=";
cin >> n;
for (int i = 2;i <= n/2; i++){
if (n % i == 0){
k = 0;
}
}
if (k == 1){
cout << "Numarul " << n << " este prim.";
} else {
cout << "Numarul " << n << " este compus.";
}
}
Explicație: