Answer the question
In order to leave comments, you need to log in
Why would the "if (j == TB_1.ColumnCount-k-1)" condition be checked for each "j"?
Completed the task "Transform the matrix by replacing the aij element with the arithmetic mean among the elements located in the i-th row and having a column number >= j". Here's how I did it:
int[,] m = new int[TB_3.RowCount,TB_3.ColumnCount];
for (int i = 0; i < TB_3.RowCount; i++)
{
for (int j = 0; j < TB_3.ColumnCount; j++)
{
m[i, j] = Convert.ToInt32(TB_3[j, i].Value);
}
}
for (int i = 0; i < TB_3.RowCount; i++)
{
for (int k = 0; k < TB_3.ColumnCount; k++)
{
double s = 0;
for (int j = 0; j < TB_3.ColumnCount-k; j++)
{
s += m[i, k + j];
if (j == TB_3.ColumnCount-k-1)
{
double sum = s / (j + 1);
TB_2[k, i].Value = sum;
}
Answer the question
In order to leave comments, you need to log in
int[,] m = new int[TB_3.RowCount,TB_3.ColumnCount];
for (int i = 0; i < TB_3.RowCount; i++)
{
for (int j = 0; j < TB_3.ColumnCount; j++)
{
m[i, j] = Convert.ToInt32(TB_3[j, i].Value);
}
}
for (int i = 0; i < TB_3.RowCount; i++)
{
for (int k = 0; k < TB_3.ColumnCount; k++)
{
double s = 0;
for (int j = 0; j < TB_3.ColumnCount-k; j++)
{
s += m[i, k + j];
}
double sum = s / (j + 1);
TB_2[k, i].Value = sum;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question