Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int factorial(int n)
- {
- if (n == 0)
- {
- return 1;
- }
- return factorial(n - 1) * n;
- }
- void countDown(int n)
- {
- if (n == 0)
- {
- return;
- }
- for (int i = 0; i < n; i++)
- {
- printf("*");
- }
- printf("\n");
- countDown(n - 1);
- for (int i = 0; i < n; i++)
- {
- printf("*");
- }
- printf("\n");
- }
- int sum(int n)
- {
- if (n == 0)
- {
- return 0;
- }
- return sum(n - 1) + n;
- }
- int sumArr(int* arr, int size, int start)
- {
- if (start == size)
- {
- return 0;
- }
- return arr[start] + sumArr(arr, size, start + 1);
- }
- int main()
- {
- int arr[] = {2, 1, 8, 7, 9};
- printf("%d\n", sumArr(arr, 5, 0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement