Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int zbir(int broj, int k) {
- if(broj == 0) {
- return 0;
- }
- int posledna_cifra = broj % 10;
- if(posledna_cifra <= k) {
- posledna_cifra = 0;
- }
- int s = zbir(broj/10, k) + posledna_cifra;
- if(posledna_cifra > k) {
- printf("%d", posledna_cifra);
- }
- return s;
- }
- int main() {
- int n, k;
- scanf("%d%d", &k, &n);
- int niza[n];
- for(int i = 0; i < n; i++) {
- scanf("%d", &niza[i]);
- }
- printf("\n");
- for(int i = 0; i < n; i++) {
- int r = zbir(niza[i], k);
- printf(" : %d\n", r);
- }
- return 0;
- }
- /*
- 5 : 5
- 4958 : 26
- 8 : 8
- 99999 : 45
- 654 : 15
- 475869 : 39
- 6 : 6
- 99 : 18
- 85 : 13
- 96 : 15
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement