Program that adds up the individual elements of 2 D Array


#include <iostream.h>
#include <conio.h>
void main ( )
{
      int i , j , sum ;
      int elements[3][7] = { {0,2,4,6,8,10,12},
                        {14,16,18,20,22,24,26},
                        {28,30,32,34,36,38,40} } ;
            for ( i = 0,sum = 0 ; i < 3 ; i++)
          {
                 for (j=0 ; j<7 ; j++)
                       sum = sum + elements[i][j] ;
          }
      cout <<"\n The result of addition = "<< sum ;
      getch ( ) ;
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|