10 maja 2017 r.
Zadanie 2. Rekurencja
arkusz maturalny: pobierz
kod źródłowy c++:
#include <iostream>
using namespace std;
int w=0;
int licz(int x){
if (x==1)
return 1;
else {
w=licz(x/2);
if (x%2)
{
w++;
return w;
}
else
{
w--;
return w;
}
}
}
int main() {
int x;
cin >> x;
cout << licz(x);
return 0;
}