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

json - Zend error Connection -

javascript - Trigger mouseenter when an animated element touches mouse -

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