Define and initiate a two-dimensional array : Array Two Dimension « Data Structure « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » Data Structure » Array Two DimensionScreenshots 
Define and initiate a two-dimensional array
Define and initiate a two-dimensional array



#include <iostream>
#include <iomanip>
using namespace std;

int matrix[3][5{ { 215314216112,  },
                     119217214111,  },
                     {  61115315316118 } };
int rowsum[3];    
int colsum[5];    
                  
int matrixsumint arr2D[][5]int vlen, int rsum[]int csum[]);
int main()
{
   cout << "Testing the function matrixsum()." << endl;

   int totalsum = matrixsummatrix, 3, rowsum, colsum);

   cout << "The matrix with the sums of rows and columns:" << endl;
   int i,j;
   fori = ; i < ; ++i)    
   {                            // matrix with row sums.
     forj = ; j < ; ++j)
       cout << setw(8<< matrix[i][j];
     cout << " | " << setw(8<< rowsum[i<< endl;
   }
   cout << endl;
   forj = ;  j < 5  ;  ++j )
     cout << setw(8<< colsum[j];
   cout << " | " << setw(8<< totalsum << endl;
   return 0;
}

int matrixsumint v[][5]int len, int rsum[]int csum[])
{  
   int ro, co;                      // Row and column index
   
   forro = ; ro < len ; ++ro)    // To compute row sums
   {
      rsum[ro0;
      forco = ; co < ; ++co)
        rsum[ro+= v[ro][co];
   }
   for(co = ; co < ; ++co)       // Compute column sums
   {
      csum[co0;
      forro = ; ro < len ; ++ro)
        csum[co+= v[ro][co];
   }
   return (rsum[0+ rsum[1+ rsum[2]);  // Total sum =
}                                       // sum of row sums.

           
       
Related examples in the same category
1.Create a two-dimensional array of objects.Create a two-dimensional array of objects.
2.Init two dimension class arrayInit two dimension class array
3.Multidimensional ArraysMultidimensional Arrays
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.