97. Maximum Subarray

 avatar
user_6817964
c_cpp
2 years ago
346 B
0
Indexable
Never
#include <stdio.h> // printf
int main()
{
	int n, x[101];
	scanf_s("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf_s("%d", &x[i]);
	}
	int sum = 0, max = 0;
	for (int i = 1; i <= n; i++) {
		sum = 0;
		for (int j = i; j <= n; j++) {
			sum = sum + x[j];
			if (sum > max) {
				max = sum;
			}
		}
	}
	printf("%d", max);

}