rabbinur

two dimensional array

Aug 16th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #define m 3
  4. #define n 4
  5.  void main()
  6.  {
  7.  int i, j, total=0;
  8.  int x[m][n]={{1,2,3,4},
  9.           {5,6,7,8},
  10.           {9,10,11,12},
  11.           };
  12.  float average;
  13.  clrscr();
  14.  //for loop, row by row
  15.  for(i=0; i<m; i++)
  16.  //for loop, column by column
  17.  for(j=0; j<n; j++)
  18.  {
  19.  cout<<"x["<<i<<"]["<<j<<"]="<<x[i][j]<<endl;
  20.  total=total+x[i][j];
  21.  }
  22.  cout<<"Total of the sequence="<<total<<endl;
  23.  average=(float)total/(float)(m*n);
  24.  cout<<"average="<<total<<"/"<<m*n<<endl;
  25.  cout<<"Average of the sequence="<<average<<endl;
  26.  getch();
  27.  }
Advertisement
Add Comment
Please, Sign In to add comment