Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int presmetaj(int broj) {
- if(broj == 0) {
- return 0;
- }
- int posledna_cifra = broj % 10;
- return presmetaj(broj / 10) + posledna_cifra;
- }
- int main(){
- int b;
- scanf("%d", &b);
- printf("%d", presmetaj(b));
- return 0;
- }
- /*
- presmetaj(541) = presmetaj(54) + 1 = 9 + 1 = 10
- presmetaj(54) = presmetaj(5) + 4 = 5 + 4 = 9
- presmetaj(5) = presmetaj(0) + 5 = 0 + 5
- presmetaj(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement