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