最大连续乘积子序列
#include <stdio.h>
#define LENGTH 8
#define min(n1, n2) (n1 > n2 ? n2 : n1)
#define max(n1, n2) (n1 > n2 ? n1 : n2)
double MaxProSub(double a[], int length);
int main()
{
double arr[LENGTH] = {-2.5, 4, 5, 0, 3, -5, 8, -1};
//double arr[LENGTH] = {-2.5, 4, 5, 0, 3, 0.5, 8, -1};
printf("%f\n", MaxProSub(arr, LENGTH));
}
double MaxProSub(double a[], int length)
{
double maxR = a[0];
double minR = a[0];
for(int i = 1; i < length; i++){
double e1 = maxR * a[i], e2 = minR * a[i];
maxR = max(max(max(e1, e2), a[i]), maxR);
minR = min(min(min(e1, e2), a[i]), minR);
printf("maxR = %f, minR = %f\n", maxR, minR);
}
return maxR;
}
最大连续乘积子数组
#include <stdio.h>
#define LENGTH 8
#