Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int sum0(int n)
- {
- return n > 0 ? sum0(n - 1) + n : 0;
- }
- int sum1(int n)
- {
- return n > 0 ? sum1(n / 10) + (n % 10) : 0;
- }
- int main ()
- {
- printf("sum0 = %d\n", sum0(1234)); // 0 + 1 + 2 + 3 + 4 + 5...n
- printf("sum1 = %d\n", sum1(1234)); // 0 + 1 + 2 + 3 + 4
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement