# Software Engineering Classroom Training--large number overflow of arrays

Source: Internet
Author: User

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

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.