Guest User

Untitled

a guest
Apr 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  ex-4
  4. //
  5. //  Created by Mohamad Nour Chawich on 12/10/11.
  6. //  Copyright (c) 2011 Syrex FZ-LLC. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. void ColumnAvg( int a[][5], double avg[], int rows);
  13. void print(const int a[][5],int rows,int columns)
  14. ;
  15.  
  16. int main ()
  17. {
  18.    
  19.     int a[3][5]= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
  20.     double avg[5];
  21.     ColumnAvg(a, avg, 3);
  22.     cout << "a[3][5]" << endl;
  23.     print(a, 3, 5);
  24.     cout << "avg[5]" << endl;
  25.     for (int j=0;j<5;j++)
  26.         cout<<" "<<avg[j];
  27.     cout<<endl;
  28.     return 0;
  29. }
  30.  
  31.  
  32. void ColumnAvg( int a[][5], double avg[], int rows){
  33.    
  34.     for (int i=0; i<5; i++) {
  35.         int colSum = 0;
  36.         for (int j=0; j<rows; j++) {
  37.             colSum += a[j][i];
  38.         }
  39.         avg[i] = colSum/3.0;
  40.     }
  41.    
  42. }
  43.  
  44. void print(const int a[][5],int rows,int columns)
  45. {
  46.     for(int i=0;i<rows;i++)
  47.     {
  48.         for (int j=0;j<columns;j++)
  49.             cout<<" "<<a[i][j];
  50.         cout<<endl;
  51.     }
  52. }
Add Comment
Please, Sign In to add comment