I am having a problem finding the average of each column in my array. I think I have the layout right, but it gives me a seg. fault when I get to the "Analyze array" section.
Code:
#include "my.h"
int main(){
int rows, columns, i, j, newrows, *temp, min, max, minrow, maxrow, avgrow;
float **array, avg, avgtemp;
scanf("%d", &rows);
scanf("%d", &columns);
newrows = rows + 3;
minrow = rows;
maxrow = rows + 1;
avgrow = rows + 2;
// Create array
array = malloc(newrows * sizeof(float));
for(i=0; i < rows; i++)
array[i] = malloc(columns * sizeof(float));
// store array
for(i=0; i <rows; i++){
for(j=0; j<columns; j++){
scanf("%d", temp);
*(*(array + i) + j) = *temp;
}
}
// Analyze array
for(i=0; i < rows; i++){
for(j=0; j < columns; j++){
avgtemp += *(*(array + i) + j);
array[avgrow][j] = avg / j;
}
}
// print array
PrintArray(array, rows, columns);
return 0;
}
I am trying to determine the average and put the answer in a row underneath. I still have two extra rows for the min and max, but if I can find out the average, the rest should fall into place. Thanx in advance.