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.
Pair of people: Huyabao Gioyan
Second, design ideas:
① deal with the problem of 1000 elements, we set the length of the array to 1000, where each element is randomly generated, because this topic is focused on the overflow problem, so we set their values are relatively large;
② at this stage we set them all to int, and when we exceed the range, the system will automatically convert to negative values, and the overflow will be displayed after judging.
1 //Pair Development-Huyabao Gioyan 2 3#include"stdafx.h" 4#include"stdlib.h" 5 6 int_tmain (intARGC, _tchar*argv[])7 { 8 inti,j,a[ +]; 9 intSum,max;Tenprintf"the randomly generated array is: \ n"); One for(j=0;j< +; j + +) A { -A[j]=rand () +100000000; -printf"%d\t", A[j]); the } - -Max = a[0]; - + for(i=0;i< +; i++) - { +Sum =0; A for(j=i;j< +; j + +) at { -Sum =sum+A[j]; - if(sum<=0) - { - //printf ("Overflow! "); -sum=0; in } - if(Sum >Max) to { +Max =Sum; - } the } * } $ Panax Notoginseng return 0; -}
Iv. Test and operation results:
Five, Experience:
This time the experiment we wrote on the basis of the original, the program automatically generated 1000 numbers, this aspect is not a problem. The result is not always correct. Our overflow is different from other classmates, not 0. Instead, it always draws an equal number. Finally set if sum<=0, the output overflows.
This knot pair development, we encountered the problem is not solved, overflow performance and other students are not the same, I and Huyabao are very anxious, although the solution is not particularly perfect, but two people in the process of cooperation become more tacit understanding.
Software Engineering Classroom Training--large number overflow of arrays