Maximum number of one-dimensional array overflow

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.

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

Contact Us

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.