Advertisement
bogdanNiculeasa

Find product => buggy

Sep 23rd, 2021
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int findProductArray(int arr[], int n);
  4. int findProductArrayRecursive(int arr[], int n, int i);
  5. using namespace std;
  6.  
  7. int main() {
  8.     int arr[] = {1, 3, 4, 5};
  9.     cout << findProductArray(arr, 6);
  10.     return 0;
  11. }
  12.  
  13. int findProductArray(int arr[], int n) {
  14.     return findProductArrayRecursive(arr, n, 0);
  15. }
  16.  
  17. int findProductArrayRecursive(int arr[], int n, int i) {
  18.     if (i == n) {
  19.         return 1;
  20.     } else {
  21.         int currentIndex = i;
  22.         return arr[currentIndex] * findProductArrayRecursive(arr, n, i+1);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement