Advertisement
vencinachev

Zadachi

Jul 7th, 2021
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int factorial(int n)
  5. {
  6.     if (n == 0)
  7.     {
  8.         return 1;
  9.     }
  10.     return factorial(n - 1) * n;
  11. }
  12.  
  13. void countDown(int n)
  14. {
  15.     if (n == 0)
  16.     {
  17.         return;
  18.     }
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         printf("*");
  22.     }
  23.     printf("\n");
  24.  
  25.     countDown(n - 1);
  26.  
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         printf("*");
  30.     }
  31.     printf("\n");
  32. }
  33.  
  34. int sum(int n)
  35. {
  36.     if (n == 0)
  37.     {
  38.         return 0;
  39.     }
  40.     return sum(n - 1) + n;
  41. }
  42.  
  43. int sumArr(int* arr, int size, int start)
  44. {
  45.     if (start == size)
  46.     {
  47.         return 0;
  48.     }
  49.     return arr[start] + sumArr(arr, size, start + 1);
  50. }
  51.  
  52. int main()
  53. {
  54.     int arr[] = {2, 1, 8, 7, 9};
  55.     printf("%d\n", sumArr(arr, 5, 0));
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement