c# - Using method add all numbers of the array -


am doing right? trying add each number of 2 dimensional array , display total. think on right track stuck if me thankful.

    int[,] = new int[3, 4]      {          { 4, -5, 12, -2},         { -9, 15, 19, 6},         { 18, -33, -1, 7}     };       private void totarray(int[,] array)        {           int sum = 0;           int rows = array.getlength(0);           int cols = array.getlength(1);           (int = 0; < rows; i++)           {               (int j = 0; j < cols; j++)               {                   sum += a[i, j];               }           }        }     private void button1_click(object sender, eventargs e)     {          totarray(a);     } 

if want display sum @ end:

int[,] = new int[3, 4]  {      { 4, -5, 12, -2},     { -9, 15, 19, 6},     { 18, -33, -1, 7} };   private void totarray(int[,] array)    {       int sum = 0;       int rows = array.getlength(0);       int cols = array.getlength(1);       (int = 0; < rows; i++)       {           (int j = 0; j < cols; j++)           {               sum += a[i, j];           }       }       messagebox.show("the sum of array " + sum.tostring() + "."); //show sum    } private void button1_click(object sender, eventargs e) {     totarray(a); } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -