Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int soberi(int broj) {
- if(broj == 0) {
- return 0;
- }
- int posledna_cifra = broj % 10;
- return soberi(broj / 10) + posledna_cifra;
- }
- int main() {
- int n;
- scanf("%d", &n);
- printf("%d\n", soberi(n));
- return 0;
- }
- // soberi(123) = soberi(12) + 3 = 3 + 3 = 6
- // soberi(12) = soberi(1) + 2 = 1 + 2 = 3
- // soberi(1) = soberi(0) + 1 = 0 + 1 = 1
- // soberi(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement