Advertisement
josiftepe

Untitled

Nov 14th, 2021
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int presmetaj(int broj) {
  5.     if(broj == 0) {
  6.         return 0;
  7.     }
  8.     int posledna_cifra = broj % 10;
  9.     return presmetaj(broj / 10) + posledna_cifra;
  10. }
  11. int main(){
  12.     int b;
  13.     scanf("%d", &b);
  14.     printf("%d", presmetaj(b));
  15.     return 0;
  16. }
  17. /*
  18.  presmetaj(541) = presmetaj(54) + 1 = 9 + 1 = 10
  19.  presmetaj(54) = presmetaj(5) + 4 = 5 + 4 = 9
  20.  presmetaj(5) = presmetaj(0) + 5 = 0 + 5
  21.  presmetaj(0) = 0
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement