c# - Given an array contains sequence of numbers from 0 to 1000. -


given array contains sequence of numbers 0 1000. use loop sum array values , break loop if sum >= 500 c#

here go:

//first initialize array  // loop on array , sum. int sum = 0; for(int i=0; < yourarray.length; i++) {     sum += yourarray[i];     if(sum >=  500)     {         break;     } } console.writeline("sum : {0}", sum); //print out sum 

here live demo


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -