First, title and requirements:
Title: Returns the and of the largest sub-array in an integer array.
Requirements (new addition): ① requires that the program must be able to handle 1000 elements; ② each element is of type Int32.
Member: Shi Li Haisu
Two experimental Thoughts
Defines an unsigned long-shaped array, finding the maximum and if the subarray is greater than longmax+1, overflow
Three experimental code
#include <iostream.h>LongMAX (unsignedLongArry[],intlength) {unsignedLongsum=arry[0]; unsignedLongmaxsum=arry[0]; for(intI=1; i<length;i++) { if(sum<0) {sum=Arry[i]; } Else{sum=sum+Arry[i]; if(sum<Long_max) {cout<<"Overflow"<<Endl; Break; } } if(maxsum<=sum) {Maxsum=sum; } } returnmaxsum;}intMain () {unsignedLonga[ +]; for(intI=0;i< +; i++) {A[i]= (unsignedLong) rand ()%5+4294967290; cout<<a[i]<<" "; } unsignedLongQ=max (A, +); cout<<Endl; cout<<Q; if(q<0) {cout<<"Overflow"<<Endl; } return 0;}
Four experiments
Five experimental experiences
In fact, we are not particularly aware of this experiment, because has not considered this aspect of the matter, I have been to this memory problem is not too cold, some can not come over, also has no clue,
And the dorm with some ideas, but still not very mature, about the overflow we are still discussing the good method, the improvement will be transmitted again
Maximum number of one-dimensional array overflow