i am trying to find the subarray that has the maximum product. the product is right, but the code i wrote doesn't seem to check for subarrays that do not start with the first element of the original array, as every time i run the code, 'first' is always 0, and the value of the maximum product is wrong if the subarray does not start from the first element. this is what i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int array[10];
int i, j, k, product, current=1, first=0, last=0, min;
srand(time(NULL));
printf("10.1\n");
printf("[");
for(i=0; i<10; i++){
array[i] = rand() % 11 - 5;
printf("%d ", array[i]);
}
printf("]\n");
min = array[0];
for(i=0; i<10; i++){
if(array[i]<min){
min = array[i];
}
}
product = min;
printf("min: %d\n", min);
for(i=0; i<10; i++){
for(j=9; j>=0; j--){
current=1;
for(k=j; k>=0; k--){
current = current*array[k];
}
if(current>product){
product = current;
first=i;
last=j;
}
}
}
printf("%d %d %d", first, last, product);
i am unsure where i wrote the code for the loops wrong, and would appreciate any help, thanks!