#include #include #include
/* main program fucntion */void main(){ int iMatrSize, // size of the matrix iSum = 0, // sum of the nessesary elements of the matrix iCnt = 0, // number of the nessesary elements of the matrix **aMatr; // the matrix int i, j;
scanf_s("%i", &iMatrSize);
/* allocation memory for the array */ aMatr = (int**)malloc(sizeof(int) * iMatrSize); for (i = 0; i < iMatrSize; i++) { aMatr[i] = (int*)malloc(sizeof(int) * iMatrSize); }
/* filling in the array */ for (i = 0; i < iMatrSize; i++) for (j = 0; j < iMatrSize; j++) aMatr[i][j] = rand() % 21 - 10;
/* counting the sum of the elements */ for (i = 0; i < iMatrSize; i++) for (j = 0; j < iMatrSize - i - 1; j++) iSum += aMatr[i][j], iCnt++;
/* outputing the array */ for (i = 0; i < iMatrSize; i++) { for (j = 0; j < iMatrSize; j++) printf ("%3i ", aMatr[i][j]); printf("\n"); }
printf("Sum = %f\n", (float)iSum / iCnt);
_getch();} /* End of 'main' function */