Advertisement
Josif_tepe

Untitled

May 27th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 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", &n, &k);
  21.     int niza[n];
  22.     for(int i = 0; i < n; i++) {
  23.         scanf("%d", &niza[i]);
  24.     }
  25.     for(int i = 0; i < n; i++) {
  26.         int r = zbir(niza[i], k);
  27.         printf(" : %d\n", r);
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement