Thread: Help in 2D C++......

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59

    Help in 2D C++......

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;
     
    void call(int array[5][6], const int i){
         
      int colRowSum[6] = {0};
      int colSumRow[5] = {0};
     
     
      //sum to column row
      for(int i = 0; i < 5; i++){
         for( int j = 0; j < 6; j++){
            colRowSum[j] += array[i][j];
             colSumRow[i] += array[i][j];
          }
      }
     
      //print array
    for(int i = 0; i != 5; ++i){
    	  for(int j = 0; j != 6; ++j){
    		  cout.width(9);
    		  cout << array[i][j];
    	  }
     
              cout.width(9);
              cout << colSumRow[i];
     
    	  cout << endl;
      }
     
     
     
      //print result
      for(int n = 0; n != 6; ++n){
    	  cout.width(9);
    	  cout << colRowSum[n] <<" ";
      }
      for (int s = 0; s != 5; ++s){
          cout.width(9);
          cout <<colSumRow[s];
      }
     
      cout << endl;
    }
     
    int main(){
        int array[ 5 ][ 6 ] = { { 141,   567,   434,   100,   269,   324, },
                                { 578,   458,   562,   564,   305,   245, },
                                { 381,   427,   561,   591,   595,   542, },
                                { 427,   536,   491,   204,   502,   253, },
                                { 392,   482,   521,   316,   318,   495, } };
     
    	call (array,5);
     
        system("pause");
    	return 0;
     
    }

    here is the correct output...i want the program to be like this....

    100 101 102 103 104 105 615
    106 107 108 109 110 111 651
    112 113 114 115 116 117 687
    118 119 120 121 122 123 723
    124 125 126 127 128 129 759
    560 565 570 575 580 585 3435

    i really need your help!>...
    Last edited by [Student]; 07-12-2011 at 07:43 AM.

Popular pages Recent additions subscribe to a feed