Advertisement
Josif_tepe

Untitled

Dec 23rd, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int rekurzija(int broj, int K) {
  6.     if(broj == 0) {
  7.         return 0; // base case, ne prodolzuvaj ponatamu
  8.     }
  9.     int digit = (broj % 10);
  10.     int ret = 0;
  11.     if(digit > K) {
  12.         ret = rekurzija(broj / 10, K) + digit;
  13.         printf("%d", digit);
  14.     }
  15.     else {
  16.         ret = rekurzija(broj / 10, K);
  17.     }
  18.     return ret;
  19. }
  20. int main()
  21. {
  22.     int K, N;
  23.     scanf("%d%d", &K, &N);
  24.     for(int i = 0; i < N; i++) {
  25.         int broj;
  26.         scanf("%d", &broj);
  27.         int suma = rekurzija(broj, K);
  28.         printf(" : %d\n", suma);
  29.        
  30.     }
  31.     return 0;
  32. }
  33. /*
  34.  
  35.  */
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement