Răspuns :
#include <iostream>using namespace std;
int main() { int a, b, c, d, nrp=0, nri=0; cin>>a; cin>>b; cin>>c; cin>>d; if(a%2==0) nrp++; else nri++; if(b%2==0) nrp++; else nri++; if(c%2==0) nrp++; else nri++; if(d%2==0) nrp++; else nri++; cout<<"sunt "<<nrp<<" numere pare si "<<nri<<" numere impare."; return 0;}
int main() { int a, b, c, d, nrp=0, nri=0; cin>>a; cin>>b; cin>>c; cin>>d; if(a%2==0) nrp++; else nri++; if(b%2==0) nrp++; else nri++; if(c%2==0) nrp++; else nri++; if(d%2==0) nrp++; else nri++; cout<<"sunt "<<nrp<<" numere pare si "<<nri<<" numere impare."; return 0;}
Iti prezint si eu o alta varianta de rezolvare (utila daca stii for)
#include <iostream>
using namespace std;
int main() {
int a, nrpare = 0, nrimpare = 0;
for(int i = 0; i < 4; i++) {
cin >> a;
if(a % 2 == 0)
nrpare++;
else
nrimpare++;
}
cout <<"Sunt " << nrpare <<" numere pare " << endl;
cout <<"Sunt " << nrimpare <<" numere impare ";
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a, nrpare = 0, nrimpare = 0;
for(int i = 0; i < 4; i++) {
cin >> a;
if(a % 2 == 0)
nrpare++;
else
nrimpare++;
}
cout <<"Sunt " << nrpare <<" numere pare " << endl;
cout <<"Sunt " << nrimpare <<" numere impare ";
return 0;
}