Salut!
Cerinta: Se citește de la tastatura un număr natural n=abcd. Numărați cifrele impare ale numărului n.
Rezolvarea:
#include <iostream>
using namespace std;
int n, a, b, c, d, nr;
int main ()
{
cin>>n;
a=n/1000;
b=(n%1000)/100;
c=(n%100)/10;
d=n%10;
if(a%2==1) nr=nr+1;
if(b%2==1) nr=nr+1;
if(c%2==1) nr=nr+1;
if(d%2==1) nr=nr+1;
cout<<nr;
return 0;
}
\SAU\
#include <iostream>
using namespace std;
int n, a, b, c, d, nr;
int main ()
{
cin>>n;
a=n/1000;
b=(n%1000)/100;
c=(n%100)/10;
d=n%10;
if(a%2==1) nr=nr+1;
if(b%2==1) nr=nr+1;
if(c%2==1) nr=nr+1;
if(d%2==1) nr=nr+1;
cout<<n<<" are"<<" "<<nr<<" cifre impare";
return 0;
}
Succes!