经典的题目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h> #define MAXN 30 int product(int a[], int start, int end) { int i, p = 1; for (i=start; i<=end; i++) p = p * a[i]; return p; } int main(int argc, char *argv[]) { int n, i, j, t; int a[MAXN]; int max; scanf("%d", &n); for (i=1; i<=n; i++) scanf("%d", &a[i]); max = a[1]; for (i=1; i<=n; i++) for (j=i; j<=n; j++) { t = product(a, i, j); if (t>max) max = t; } if (max >=0) printf("%d", max); else printf("%d", -1); return 0; } |