Advertisement
Josif_tepe

Untitled

Nov 14th, 2023
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int rek(int x, int pogolemi, int pomali) {
  4.     if(x == 0) {
  5.         if(pogolemi > pomali) {
  6.             return 1;
  7.         }
  8.         else {
  9.             return 2;
  10.         }
  11.     }
  12.    
  13.     int cifra = x % 10;
  14.     if(cifra > 4) {
  15.         return rek(x / 10, pogolemi + 1, pomali);
  16.     }
  17.     else {
  18.         return rek(x / 10, pogolemi, pomali + 1);
  19.     }
  20. }
  21. int main () {
  22.  
  23.     int n;
  24.     scanf("%d", &n);
  25.    
  26.     printf("%d\n", rek(n, 0, 0));
  27.  
  28. return 0;
  29.  
  30. }
  31. // rek(123456, 0, 0) = rek(12345, 1, 0) = 2
  32. // rek(12345, 1, 0) = rek(1234, 2, 0) = 2
  33. // rek(1234, 2, 0) = rek(123, 2, 1) = 2
  34. // rek(123, 2, 1) = rek(12, 2, 2) = 2
  35. // rek(12, 2, 2) = rek(1, 2, 3) = 2
  36. // rek(1, 2, 3) = rek(0, 2, 4) = 2
  37. // rek(0, 2, 4) = 2
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement