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