Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int rek(int x, int pogolemi, int pomali) {
- if(x == 0) {
- if(pogolemi > pomali) {
- return 1;
- }
- else {
- return 2;
- }
- }
- int cifra = x % 10;
- if(cifra > 4) {
- return rek(x / 10, pogolemi + 1, pomali);
- }
- else {
- return rek(x / 10, pogolemi, pomali + 1);
- }
- }
- int main () {
- int n;
- scanf("%d", &n);
- printf("%d\n", rek(n, 0, 0));
- return 0;
- }
- // rek(123456, 0, 0) = rek(12345, 1, 0) = 2
- // rek(12345, 1, 0) = rek(1234, 2, 0) = 2
- // rek(1234, 2, 0) = rek(123, 2, 1) = 2
- // rek(123, 2, 1) = rek(12, 2, 2) = 2
- // rek(12, 2, 2) = rek(1, 2, 3) = 2
- // rek(1, 2, 3) = rek(0, 2, 4) = 2
- // rek(0, 2, 4) = 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement