#include<iostream> #define n 100 using namespace std; void main() { int a[n], b[n][n]; int length, i, j, w = 0, p = 0, q = 0, temp, m; cout << "请输入数组的值" << endl; for (length = 0;;) { cin >> a[length]; length++; if (getchar() == '\n') { break; } } cout << "这个数组的长度为:" << length << endl; for (i = 0; i<length; i++) { m = i; w = 0; j = 0; while (j <= length - 1) { w += a[m]; b[i][j] = w; m++; if (m>length - 1) { m = 0; } j++; } } temp = b[0][0]; for (i = 0; i<length; i++) { for (j = 0; j<length; j++) { if (b[i][j]>temp) { temp = b[i][j]; p = i; q = j; } } } cout << "最大子数组的值为:" << temp << endl; cout << endl; }
这次的循环数组是我与我的伙伴吴强共同完成的,在老师环状剪切的提示下思考