Advertisement
18126

Day3(ex8)

Jul 8th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. float sum(float a[6], int len, float s) {
  6.     if(len < 0) {
  7.         return s;
  8.     }
  9.     len = len - 1;
  10.     s = s + a[len];
  11.     return sum(a, len, s);
  12. }
  13.  
  14. int main() {
  15.     float arr[6] = {5.35, 3, 2, 6, 7, 0};
  16.     int len = 6;
  17.     float s = 0;
  18.     printf("Sum: %f", sum(arr, len, s));
  19.     return EXIT_SUCCESS;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement