Advertisement
Josif_tepe

Untitled

May 27th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int zbir(int broj, int k) {
  5.     if(broj == 0) {
  6.         return 0;
  7.     }
  8.     int posledna_cifra = broj % 10;
  9.     if(posledna_cifra <= k) {
  10.         posledna_cifra = 0;
  11.     }
  12.     int s =  zbir(broj/10, k) + posledna_cifra;
  13.     if(posledna_cifra > k) {
  14.         printf("%d", posledna_cifra);
  15.     }
  16.     return s;
  17. }
  18. int main() {
  19.     int n, k;
  20.     scanf("%d%d", &k, &n);
  21.     int niza[n];
  22.     for(int i = 0; i < n; i++) {
  23.         scanf("%d", &niza[i]);
  24.     }
  25.     printf("\n");
  26.     for(int i = 0; i < n; i++) {
  27.         int r = zbir(niza[i], k);
  28.         printf(" : %d\n", r);
  29.     }
  30.     return 0;
  31. }
  32. /*
  33.  
  34.  
  35.  5 : 5
  36.  4958 : 26
  37.  8 : 8
  38.  99999 : 45
  39.  654 : 15
  40.  475869 : 39
  41.  6 : 6
  42.  99 : 18
  43.  85 : 13
  44.  96 : 15
  45.  **/
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement