The purpose of this exercise is to use the twosubscript meth
Solution
#include<stdio.h>
#include<stdlib.h>
#define ROW 3
#define COL 5
int main(){
//scaning data from file
freopen(\"testdata2\",\"r\",stdin); //comment this line to read from user input console
int i,j;
float *data[ROW];
for(i=0;i<ROW;i++){
float *row = (float*) malloc(sizeof(float)*COL);
for(j=0;j<COL;j++){
scanf(\"%f\", &row[j]);
}
data[i] = row;
}
//average of rows
printf(\"The average values for the three rows are: \");
for(i=0;i<ROW;i++){
float sum = 0;
for(j=0;j<COL;j++){
sum += data[i][j];
}
printf(\"%.2f \", sum/COL);
}
//average of columns
printf(\"\ The average values for the three columns are: \");
for(i=0;i<COL;i++){
float sum = 0;
for(j=0;j<ROW;j++){
sum += data[j][i];
}
printf(\"%.2f \", sum/ROW);
}
}
