Arkusz
Rozwiązanie
Zasady oceniania i sprawozdanie
Zapis w C++:
#include <iostream>
using namespace std;
int licz(int x) {
if (x == 1) {
return 1;
} else {
int w = licz(x / 2);
if (x % 2 == 1) {
return w + 1;
} else {
return w - 1;
}
}
}
main() {
int x;
cout << "Podaj wartosc x: ";
cin >> x;
cout<<"Wynik dla x = "<< x<<": "<<licz(x)<<endl;
return 0;
}
using namespace std;
int licz(int x) {
if (x == 1) {
return 1;
} else {
int w = licz(x / 2);
if (x % 2 == 1) {
return w + 1;
} else {
return w - 1;
}
}
}
main() {
int x;
cout << "Podaj wartosc x: ";
cin >> x;
cout<<"Wynik dla x = "<< x<<": "<<licz(x)<<endl;
return 0;
}
def licz(x):
if x == 1:
return 1
else:
w = licz(x // 2)
if x % 2 == 1:
return w + 1
else:
return w - 1
x = int(input("Wpisz wartość x: "))
w = licz(x)
print(f"Wynik: {w}")
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Wpisz wartosc x: ");
int x = scanner.nextInt();
int wynik = licz(x);
System.out.println("Wynik: " + wynik);
}
public static int licz(int x) {
if (x == 1) {
return 1;
} else {
int w = licz(x / 2);
if (x % 2 == 1) {
return w + 1;
} else {
return w - 1;
}
}
}
}