Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // ex-4
- //
- // Created by Mohamad Nour Chawich on 12/10/11.
- // Copyright (c) 2011 Syrex FZ-LLC. All rights reserved.
- //
- #include <iostream>
- using namespace std;
- void ColumnAvg( int a[][5], double avg[], int rows);
- void print(const int a[][5],int rows,int columns)
- ;
- int main ()
- {
- int a[3][5]= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
- double avg[5];
- ColumnAvg(a, avg, 3);
- cout << "a[3][5]" << endl;
- print(a, 3, 5);
- cout << "avg[5]" << endl;
- for (int j=0;j<5;j++)
- cout<<" "<<avg[j];
- cout<<endl;
- return 0;
- }
- void ColumnAvg( int a[][5], double avg[], int rows){
- for (int i=0; i<5; i++) {
- int colSum = 0;
- for (int j=0; j<rows; j++) {
- colSum += a[j][i];
- }
- avg[i] = colSum/3.0;
- }
- }
- void print(const int a[][5],int rows,int columns)
- {
- for(int i=0;i<rows;i++)
- {
- for (int j=0;j<columns;j++)
- cout<<" "<<a[i][j];
- cout<<endl;
- }
- }
Add Comment
Please, Sign In to add comment