JSFiddle - React, Tailwind, and code Playground
JavaScript
var k;
var i;
var temp;
//Declare an 8x8 matrix
var MAT = new Array (8)
for (i=0; i<8; i++) {
MAT[i] = new Array (8);
//Populate the matrix
for (k=0; k<8;k++) {
MAT[i][k] = Math.floor(Math.random() * 64);
}
}
//Create Array of length 22
var grades = new Array (22);
for (i=0; i<8; i++) {
grades[i] = MAT[0][i]; //Top row of matrix into the array.
grades[i+7] = MAT[6][i]; //Anti-diagonal row of matrix into the array.
i=i+1;
k=k-1;
grades[i+14] = MAT[7][i] //Bottom row of matrix into the array.
}
//Sort the array
for (i=0; I < 63; i= i++) {
for (k=i+1; k<64; k++) {
if (grades[i] > grades[k]) {
temp = grades [k];
grades[k] = grades [i];
grades[i] = temp;
}
}
}
//Compute the average of the grades stored in the even locations of the array.
var sum =0;
var avg;
for (i=0; i<100; i ++ 2) {
sum=sum + grades [i];
}
avg = sum/50;
document.write (avg);
//Copy the array back into the matrix
i=0;
for (k=0; k<8; k++) {
MAT[i][k] = grades[i];
i = i+1;
k=6
for i=1; i <7; i++) {
MAT[i][k] = grades [i];
i=i+1;
k=k-1;
i=7
for (k=1; k<8; k+1) {
MAT[i][k] = grades [i];
}
}
}
//Display matrix
document.write ( + MAT +);