SJMormo

Untitled

Sep 29th, 2020
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int seven;
  7.  
  8. int recursion(int arr[], int pos, int n)
  9. {
  10. if (pos == n) return 0;
  11.  
  12. if (pos == 0) seven = 1;
  13. else seven *= 7;
  14.  
  15. return (seven * arr[pos]) + recursion(arr, pos + 1, n);
  16. }
  17.  
  18. int main()
  19. {
  20. int n = 6;
  21. int arr[6] = {2, 4, 5, -1, 4, 6};
  22. int ans = recursion(arr, 0, n);
  23. cout << ans << '\n';
  24.  
  25. return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment