#include <iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int i;
int a[10000];
int max = 0;
int b = 0;
srand(time(NULL));
cout<<"数组为:"<<endl;
for (i = 0; i<10000; i++)
{
a[i] = rand()*4294967296 ;
}
for (i = 0; i<10000; i++)
{
cout << a[i] << ‘\t‘;
}
cout << endl;
for (i = 0; i < 10000; i++)
{
b += a[i];
if (b < 0)
b = 0;
if (b > max)
max = b;
}
if (max == 0)
{
max = a[0];
for (i = 0; i < 10000; i++)
{
if (max < a[i])
{
max = a[i];
}
}
}
cout <<"最大子数组为:"<< max << endl;
system("pause");
return 0;
}
截图:

感想:
有的时候程序运行结果会是都是0,这好像是因为数据过多导致程序出错,数据长度减少就可以解决了。程序比较难,需要多加考虑。