- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想获取数组的每一行和每一列的总和,然后用C一张一张地打印出来。我完成了一半的工作,但无法继续进行下去。这是我的代码:
int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{
int sum_of_column1=0;
int sum_of_row1;
for(j=0,i=0;i<r;i++)
{
sum_of_column1=sum_of_column1+array[i][j];
if(i==r-1)
{
printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
j=j+1;
}
}
for(i=0,j=0;j<r;j++)
{
sum_of_row1=sum_of_row1+array[i][j];
if(j=c-1)
{
printf("\nSum of %d.row: %d\n",j+1,sum_of_row1);
i=i+1;
}
}
i=0;
printf("\nSum of %d.column: %d\n",j+1,sum_of_column1);
j=j+1
i=0;
最佳答案
任务的建议代码
你有:
int n,m;
void sum_row_column(int array[n][m],int r,int c,int i,int j)
{
n
和
m
设置不正确,则不必要地导致失败。不需要该级别的耦合,并且如果您确实使用该级别的耦合,则变量
r
和
c
是多余的。您应该使用:
void print_sum_rows_cols(int r, int c, int array[r][c])
{
n
和
m
应该是不必要的;参数
i
和
j
似乎也毫无意义,因为您忽略了传递给函数的值,并在循环开始时将它们都设置为
0
。
for (int col = 0; col < c; col++)
{
int colsum = 0;
for (int row = 0; row < r; row++)
colsum += array[row][col];
printf("Sum for col %d = %d\n", col, colsum);
}
for (int row = 0; row < r; row++)
{
int rowsum = 0;
for (int col = 0; col < c; col++)
rowsum += array[row][col];
printf("Sum for row %d = %d\n", row, rowsum);
}
#include <stdio.h>
static void print_sum_rows_cols(int r, int c, int array[r][c])
{
for (int col = 0; col < c; col++)
{
int colsum = 0;
for (int row = 0; row < r; row++)
colsum += array[row][col];
printf("Sum for col %d = %d\n", col, colsum);
}
for (int row = 0; row < r; row++)
{
int rowsum = 0;
for (int col = 0; col < c; col++)
rowsum += array[row][col];
printf("Sum for row %d = %d\n", row, rowsum);
}
}
static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
printf("%s (%dx%d):\n", tag, rows, cols);
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
printf("%3d", matrix[r][c]);
putchar('\n');
}
}
int main(void)
{
int a1[3][4] =
{
{ 68, 78, 50, 46, },
{ 64, 12, 47, 1, },
{ 86, 10, 84, 62, },
};
int a2[5][3] =
{
{ 4, 30, 19, },
{ 79, 58, 20, },
{ 95, 12, 24, },
{ 20, 37, 72, },
{ 17, 0, 53, },
};
dump_matrix("A1", 3, 4, a1);
print_sum_rows_cols(3, 4, a1);
dump_matrix("A2", 5, 3, a2);
print_sum_rows_cols(5, 3, a2);
return 0;
}
print_sum_rows_cols()
函数中的代码保留了问题的变量名,尽管它们不是我在自己的代码中使用的名称。 (对于这些,请参阅“其他答案的分析”部分。)
A1 (3x4):
68 78 50 46
64 12 47 1
86 10 84 62
Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242
A2 (5x3):
4 30 19
79 58 20
95 12 24
20 37 72
17 0 53
Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70
int n;
int m;
void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
int sumOfColumn = 0;
int sumOfRow = 0;
printf("\n");
for (i = 0; i < r; i++)
{
sumOfRow = 0;
for (j = 0; j < c; j++)
{
sumOfRow += array[i][j];
}
printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
}
printf("\n");
for (j = 0; j < r; j++)
{
sumOfColumn = 0;
for (i = 0; i < c; i++)
{
sumOfColumn += array[i][j];
}
printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
}
}
n
和
m
中的值标识。
r
和
c
标识。
i
和
j
中的值未使用;它们只是定义两个局部循环变量的一种特殊方式。
assert(n == r && m == c);
,则第一对嵌套循环(对行进行求和)就可以了。
assert(n == r && m == c && n == m):
(方阵),第二对嵌套循环(将列求和)是可以的,但这主要是偶然的而不是设计。
r
x
c
,但是该函数假定数组的大小为
m
x
n
。
bogus_sum_rows_cols()
)还有一个'假'变体,它使用
n
和
m
变量来调整数组的大小;当
n
和
m
与
r
和
c
不同步时,它将产生错误的答案。提议的答案(
bogus_sum_row_column()
)还有一个'假'变体,如果
r
和
c
中的数组大小与
n
和
m
都匹配,则至少可以正确地对列求和。
/* SO 47719-9719 - Abuse of VLA definitions (and notations) */
#include <stdio.h>
static int debug = 0;
// Original answer (renamed variables, reordered results, and print row/col + 1)
static void print_sum_rows_cols(int rows, int cols, int array[rows][cols])
{
for (int r = 0; r < rows; r++)
{
int rowsum = 0;
for (int c = 0; c < cols; c++)
{
if (debug)
printf(" a[%d][%d] = %d", r, c, array[r][c]);
rowsum += array[r][c];
}
if (debug)
putchar('\n');
printf("Sum for row %d = %d\n", r + 1, rowsum);
}
putchar('\n');
for (int c = 0; c < cols; c++)
{
int colsum = 0;
for (int r = 0; r < rows; r++)
{
if (debug)
printf(" a[%d][%d] = %d", r, c, array[r][c]);
colsum += array[r][c];
}
if (debug)
putchar('\n');
printf("Sum for col %d = %d\n", c + 1, colsum);
}
}
static int n; // Rows
static int m; // Columns
// Adapted print_sum_rows_cols with size from n, m
// Using n, m is unnecessary coupling (and can lead to erroneous results)
static void bogus_sum_rows_cols(int array[n][m], int rows, int cols)
{
for (int r = 0; r < rows; r++)
{
int rowsum = 0;
for (int c = 0; c < cols; c++)
{
if (debug)
printf(" a[%d][%d] = %d", r, c, array[r][c]);
rowsum += array[r][c];
}
if (debug)
putchar('\n');
printf("Sum for row %d = %d\n", r, rowsum);
}
putchar('\n');
for (int c = 0; c < cols; c++)
{
int colsum = 0;
for (int r = 0; r < rows; r++)
{
if (debug)
printf(" a[%d][%d] = %d", r, c, array[r][c]);
colsum += array[r][c];
}
if (debug)
putchar('\n');
printf("Sum for col %d = %d\n", c, colsum);
}
}
// Original answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus. The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void sum_row_column(int array[n][m], int r, int c, int i, int j)
{
int sumOfColumn = 0;
int sumOfRow = 0;
printf("\n");
for (i = 0; i < r; i++)
{
sumOfRow = 0;
for (j = 0; j < c; j++)
{
if (debug)
printf(" a[%d][%d] = %d", i, j, array[i][j]);
sumOfRow += array[i][j];
}
if (debug)
putchar('\n');
printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
}
printf("\n");
for (j = 0; j < r; j++)
{
sumOfColumn = 0;
for (i = 0; i < c; i++)
{
if (debug)
printf(" a[%d][%d] = %d", i, j, array[i][j]);
sumOfColumn += array[i][j];
}
if (debug)
putchar('\n');
printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
}
}
// Semi-fixed answer from OP - bogus results (debug printing added).
// Using n, m is unnecessary coupling (and can lead to erroneous results)
// Using i, j as arguments is bogus; the values passed in are ignored
// The 'sum column' loops are completely bogus. The outer loop should
// iterate over columns [0..c) and the inner loop over rows [0..r).
// See print_sum_rows_cols() for the correct (minimal) interface.
static void bogus_sum_row_column(int array[n][m], int r, int c, int i, int j)
{
int sumOfColumn = 0;
int sumOfRow = 0;
printf("\n");
for (i = 0; i < r; i++)
{
sumOfRow = 0;
for (j = 0; j < c; j++)
{
if (debug)
printf(" a[%d][%d] = %d", i, j, array[i][j]);
sumOfRow += array[i][j];
}
if (debug)
putchar('\n');
printf("Sum of %d.row=%d\n", i + 1, sumOfRow);
}
printf("\n");
for (j = 0; j < c; j++) // c, not r
{
sumOfColumn = 0;
for (i = 0; i < r; i++) // r, not c
{
if (debug)
printf(" a[%d][%d] = %d", i, j, array[i][j]);
sumOfColumn += array[i][j];
}
if (debug)
putchar('\n');
printf("Sum of %d.column=%d\n", j + 1, sumOfColumn);
}
}
static void dump_matrix(const char *tag, int rows, int cols, int matrix[rows][cols])
{
printf("Matrix %s (%dx%d):\n", tag, rows, cols);
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
printf("%3d", matrix[r][c]);
putchar('\n');
}
}
static void test_sequence(int v_debug, int v_n, int v_m, const char *tag,
int rows, int cols, int matrix[rows][cols])
{
debug = v_debug;
n = v_n;
m = v_m;
dump_matrix(tag, rows, cols, matrix);
printf("\nprint_sum_rows_cols():\n");
print_sum_rows_cols(rows, cols, matrix);
printf("\nbogus_sum_rows_cols() - (n = %d, m = %d):\n", n, m);
bogus_sum_rows_cols(matrix, rows, cols);
printf("\nsum_row_column()(n = %d, m = %d):\n", n, m);
sum_row_column(matrix, rows, cols, -1, -1);
printf("\nbogus_sum_row_column()(n = %d, m = %d):\n", n, m);
bogus_sum_row_column(matrix, rows, cols, -1, -1);
putchar('\n');
}
static void test_matrix_summation(const char *tag, int rows, int cols, int matrix[rows][cols])
{
test_sequence(1, 2, 2, tag, rows, cols, matrix);
test_sequence(0, rows, cols, tag, rows, cols, matrix);
}
int main(void)
{
int a1[3][4] =
{
{ 68, 78, 50, 46, },
{ 64, 12, 47, 1, },
{ 86, 10, 84, 62, },
};
int a2[5][3] =
{
{ 4, 30, 19, },
{ 79, 58, 20, },
{ 95, 12, 24, },
{ 20, 37, 72, },
{ 17, 0, 53, },
};
int a3[3][3] =
{
{ 96, 84, 13, },
{ 63, 29, 80, },
{ 97, 98, 48, },
};
test_matrix_summation("A1", 3, 4, a1);
test_matrix_summation("A2", 5, 3, a2);
test_matrix_summation("A3", 3, 3, a3);
return 0;
}
Matrix A1 (3x4):
68 78 50 46
64 12 47 1
86 10 84 62
print_sum_rows_cols():
a[0][0] = 68 a[0][1] = 78 a[0][2] = 50 a[0][3] = 46
Sum for row 1 = 242
a[1][0] = 64 a[1][1] = 12 a[1][2] = 47 a[1][3] = 1
Sum for row 2 = 124
a[2][0] = 86 a[2][1] = 10 a[2][2] = 84 a[2][3] = 62
Sum for row 3 = 242
a[0][0] = 68 a[1][0] = 64 a[2][0] = 86
Sum for col 1 = 218
a[0][1] = 78 a[1][1] = 12 a[2][1] = 10
Sum for col 2 = 100
a[0][2] = 50 a[1][2] = 47 a[2][2] = 84
Sum for col 3 = 181
a[0][3] = 46 a[1][3] = 1 a[2][3] = 62
Sum for col 4 = 109
bogus_sum_rows_cols() - (n = 2, m = 2):
a[0][0] = 68 a[0][1] = 78 a[0][2] = 50 a[0][3] = 46
Sum for row 0 = 242
a[1][0] = 50 a[1][1] = 46 a[1][2] = 64 a[1][3] = 12
Sum for row 1 = 172
a[2][0] = 64 a[2][1] = 12 a[2][2] = 47 a[2][3] = 1
Sum for row 2 = 124
a[0][0] = 68 a[1][0] = 50 a[2][0] = 64
Sum for col 0 = 182
a[0][1] = 78 a[1][1] = 46 a[2][1] = 12
Sum for col 1 = 136
a[0][2] = 50 a[1][2] = 64 a[2][2] = 47
Sum for col 2 = 161
a[0][3] = 46 a[1][3] = 12 a[2][3] = 1
Sum for col 3 = 59
sum_row_column()(n = 2, m = 2):
a[0][0] = 68 a[0][1] = 78 a[0][2] = 50 a[0][3] = 46
Sum of 1.row=242
a[1][0] = 50 a[1][1] = 46 a[1][2] = 64 a[1][3] = 12
Sum of 2.row=172
a[2][0] = 64 a[2][1] = 12 a[2][2] = 47 a[2][3] = 1
Sum of 3.row=124
a[0][0] = 68 a[1][0] = 50 a[2][0] = 64 a[3][0] = 47
Sum of 1.column=229
a[0][1] = 78 a[1][1] = 46 a[2][1] = 12 a[3][1] = 1
Sum of 2.column=137
a[0][2] = 50 a[1][2] = 64 a[2][2] = 47 a[3][2] = 86
Sum of 3.column=247
bogus_sum_row_column()(n = 2, m = 2):
a[0][0] = 68 a[0][1] = 78 a[0][2] = 50 a[0][3] = 46
Sum of 1.row=242
a[1][0] = 50 a[1][1] = 46 a[1][2] = 64 a[1][3] = 12
Sum of 2.row=172
a[2][0] = 64 a[2][1] = 12 a[2][2] = 47 a[2][3] = 1
Sum of 3.row=124
a[0][0] = 68 a[1][0] = 50 a[2][0] = 64
Sum of 1.column=182
a[0][1] = 78 a[1][1] = 46 a[2][1] = 12
Sum of 2.column=136
a[0][2] = 50 a[1][2] = 64 a[2][2] = 47
Sum of 3.column=161
a[0][3] = 46 a[1][3] = 12 a[2][3] = 1
Sum of 4.column=59
Matrix A1 (3x4):
68 78 50 46
64 12 47 1
86 10 84 62
print_sum_rows_cols():
Sum for row 1 = 242
Sum for row 2 = 124
Sum for row 3 = 242
Sum for col 1 = 218
Sum for col 2 = 100
Sum for col 3 = 181
Sum for col 4 = 109
bogus_sum_rows_cols() - (n = 3, m = 4):
Sum for row 0 = 242
Sum for row 1 = 124
Sum for row 2 = 242
Sum for col 0 = 218
Sum for col 1 = 100
Sum for col 2 = 181
Sum for col 3 = 109
sum_row_column()(n = 3, m = 4):
Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242
Sum of 1.column=222
Sum of 2.column=130
Sum of 3.column=200
bogus_sum_row_column()(n = 3, m = 4):
Sum of 1.row=242
Sum of 2.row=124
Sum of 3.row=242
Sum of 1.column=218
Sum of 2.column=100
Sum of 3.column=181
Sum of 4.column=109
Matrix A2 (5x3):
4 30 19
79 58 20
95 12 24
20 37 72
17 0 53
print_sum_rows_cols():
a[0][0] = 4 a[0][1] = 30 a[0][2] = 19
Sum for row 1 = 53
a[1][0] = 79 a[1][1] = 58 a[1][2] = 20
Sum for row 2 = 157
a[2][0] = 95 a[2][1] = 12 a[2][2] = 24
Sum for row 3 = 131
a[3][0] = 20 a[3][1] = 37 a[3][2] = 72
Sum for row 4 = 129
a[4][0] = 17 a[4][1] = 0 a[4][2] = 53
Sum for row 5 = 70
a[0][0] = 4 a[1][0] = 79 a[2][0] = 95 a[3][0] = 20 a[4][0] = 17
Sum for col 1 = 215
a[0][1] = 30 a[1][1] = 58 a[2][1] = 12 a[3][1] = 37 a[4][1] = 0
Sum for col 2 = 137
a[0][2] = 19 a[1][2] = 20 a[2][2] = 24 a[3][2] = 72 a[4][2] = 53
Sum for col 3 = 188
bogus_sum_rows_cols() - (n = 2, m = 2):
a[0][0] = 4 a[0][1] = 30 a[0][2] = 19
Sum for row 0 = 53
a[1][0] = 19 a[1][1] = 79 a[1][2] = 58
Sum for row 1 = 156
a[2][0] = 58 a[2][1] = 20 a[2][2] = 95
Sum for row 2 = 173
a[3][0] = 95 a[3][1] = 12 a[3][2] = 24
Sum for row 3 = 131
a[4][0] = 24 a[4][1] = 20 a[4][2] = 37
Sum for row 4 = 81
a[0][0] = 4 a[1][0] = 19 a[2][0] = 58 a[3][0] = 95 a[4][0] = 24
Sum for col 0 = 200
a[0][1] = 30 a[1][1] = 79 a[2][1] = 20 a[3][1] = 12 a[4][1] = 20
Sum for col 1 = 161
a[0][2] = 19 a[1][2] = 58 a[2][2] = 95 a[3][2] = 24 a[4][2] = 37
Sum for col 2 = 233
sum_row_column()(n = 2, m = 2):
a[0][0] = 4 a[0][1] = 30 a[0][2] = 19
Sum of 1.row=53
a[1][0] = 19 a[1][1] = 79 a[1][2] = 58
Sum of 2.row=156
a[2][0] = 58 a[2][1] = 20 a[2][2] = 95
Sum of 3.row=173
a[3][0] = 95 a[3][1] = 12 a[3][2] = 24
Sum of 4.row=131
a[4][0] = 24 a[4][1] = 20 a[4][2] = 37
Sum of 5.row=81
a[0][0] = 4 a[1][0] = 19 a[2][0] = 58
Sum of 1.column=81
a[0][1] = 30 a[1][1] = 79 a[2][1] = 20
Sum of 2.column=129
a[0][2] = 19 a[1][2] = 58 a[2][2] = 95
Sum of 3.column=172
a[0][3] = 79 a[1][3] = 20 a[2][3] = 12
Sum of 4.column=111
a[0][4] = 58 a[1][4] = 95 a[2][4] = 24
Sum of 5.column=177
bogus_sum_row_column()(n = 2, m = 2):
a[0][0] = 4 a[0][1] = 30 a[0][2] = 19
Sum of 1.row=53
a[1][0] = 19 a[1][1] = 79 a[1][2] = 58
Sum of 2.row=156
a[2][0] = 58 a[2][1] = 20 a[2][2] = 95
Sum of 3.row=173
a[3][0] = 95 a[3][1] = 12 a[3][2] = 24
Sum of 4.row=131
a[4][0] = 24 a[4][1] = 20 a[4][2] = 37
Sum of 5.row=81
a[0][0] = 4 a[1][0] = 19 a[2][0] = 58 a[3][0] = 95 a[4][0] = 24
Sum of 1.column=200
a[0][1] = 30 a[1][1] = 79 a[2][1] = 20 a[3][1] = 12 a[4][1] = 20
Sum of 2.column=161
a[0][2] = 19 a[1][2] = 58 a[2][2] = 95 a[3][2] = 24 a[4][2] = 37
Sum of 3.column=233
Matrix A2 (5x3):
4 30 19
79 58 20
95 12 24
20 37 72
17 0 53
print_sum_rows_cols():
Sum for row 1 = 53
Sum for row 2 = 157
Sum for row 3 = 131
Sum for row 4 = 129
Sum for row 5 = 70
Sum for col 1 = 215
Sum for col 2 = 137
Sum for col 3 = 188
bogus_sum_rows_cols() - (n = 5, m = 3):
Sum for row 0 = 53
Sum for row 1 = 157
Sum for row 2 = 131
Sum for row 3 = 129
Sum for row 4 = 70
Sum for col 0 = 215
Sum for col 1 = 137
Sum for col 2 = 188
sum_row_column()(n = 5, m = 3):
Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70
Sum of 1.column=178
Sum of 2.column=100
Sum of 3.column=63
Sum of 4.column=194
Sum of 5.column=107
bogus_sum_row_column()(n = 5, m = 3):
Sum of 1.row=53
Sum of 2.row=157
Sum of 3.row=131
Sum of 4.row=129
Sum of 5.row=70
Sum of 1.column=215
Sum of 2.column=137
Sum of 3.column=188
Matrix A3 (3x3):
96 84 13
63 29 80
97 98 48
print_sum_rows_cols():
a[0][0] = 96 a[0][1] = 84 a[0][2] = 13
Sum for row 1 = 193
a[1][0] = 63 a[1][1] = 29 a[1][2] = 80
Sum for row 2 = 172
a[2][0] = 97 a[2][1] = 98 a[2][2] = 48
Sum for row 3 = 243
a[0][0] = 96 a[1][0] = 63 a[2][0] = 97
Sum for col 1 = 256
a[0][1] = 84 a[1][1] = 29 a[2][1] = 98
Sum for col 2 = 211
a[0][2] = 13 a[1][2] = 80 a[2][2] = 48
Sum for col 3 = 141
bogus_sum_rows_cols() - (n = 2, m = 2):
a[0][0] = 96 a[0][1] = 84 a[0][2] = 13
Sum for row 0 = 193
a[1][0] = 13 a[1][1] = 63 a[1][2] = 29
Sum for row 1 = 105
a[2][0] = 29 a[2][1] = 80 a[2][2] = 97
Sum for row 2 = 206
a[0][0] = 96 a[1][0] = 13 a[2][0] = 29
Sum for col 0 = 138
a[0][1] = 84 a[1][1] = 63 a[2][1] = 80
Sum for col 1 = 227
a[0][2] = 13 a[1][2] = 29 a[2][2] = 97
Sum for col 2 = 139
sum_row_column()(n = 2, m = 2):
a[0][0] = 96 a[0][1] = 84 a[0][2] = 13
Sum of 1.row=193
a[1][0] = 13 a[1][1] = 63 a[1][2] = 29
Sum of 2.row=105
a[2][0] = 29 a[2][1] = 80 a[2][2] = 97
Sum of 3.row=206
a[0][0] = 96 a[1][0] = 13 a[2][0] = 29
Sum of 1.column=138
a[0][1] = 84 a[1][1] = 63 a[2][1] = 80
Sum of 2.column=227
a[0][2] = 13 a[1][2] = 29 a[2][2] = 97
Sum of 3.column=139
bogus_sum_row_column()(n = 2, m = 2):
a[0][0] = 96 a[0][1] = 84 a[0][2] = 13
Sum of 1.row=193
a[1][0] = 13 a[1][1] = 63 a[1][2] = 29
Sum of 2.row=105
a[2][0] = 29 a[2][1] = 80 a[2][2] = 97
Sum of 3.row=206
a[0][0] = 96 a[1][0] = 13 a[2][0] = 29
Sum of 1.column=138
a[0][1] = 84 a[1][1] = 63 a[2][1] = 80
Sum of 2.column=227
a[0][2] = 13 a[1][2] = 29 a[2][2] = 97
Sum of 3.column=139
Matrix A3 (3x3):
96 84 13
63 29 80
97 98 48
print_sum_rows_cols():
Sum for row 1 = 193
Sum for row 2 = 172
Sum for row 3 = 243
Sum for col 1 = 256
Sum for col 2 = 211
Sum for col 3 = 141
bogus_sum_rows_cols() - (n = 3, m = 3):
Sum for row 0 = 193
Sum for row 1 = 172
Sum for row 2 = 243
Sum for col 0 = 256
Sum for col 1 = 211
Sum for col 2 = 141
sum_row_column()(n = 3, m = 3):
Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243
Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141
bogus_sum_row_column()(n = 3, m = 3):
Sum of 1.row=193
Sum of 2.row=172
Sum of 3.row=243
Sum of 1.column=256
Sum of 2.column=211
Sum of 3.column=141
main()
程序中定义的矩阵的行和列的实际总和有关。
n
和
m
(并且既不需要
r
也
c
)。但是您不应该将函数与所有全局变量联系在一起。您应该定义
r
和
c
(如果矩阵必须为正方形,则只能定义其中之一)。
n
和
m
中的值未记录在问题或建议的答案中,因此有必要弄清楚它们表示的含义。
关于c - 二维数组(C)中每一行和每一列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47719719/
我正在 csv 上使用 hadoop 来分析一些数据。我使用sql/mysql(不确定)来分析数据,现在陷入了僵局。 我花了好几个小时在谷歌上搜索,却没有找到任何相关的东西。我需要一个查询,在该查询中
我正在为 Bootstrap 网格布局的“简单”任务而苦苦挣扎。我希望在大视口(viewport)上有 4 列,然后在中型设备上有 2 列,最后在较小的设备上只有 1 列。 当我测试我的代码片段时,似
对于这个令人困惑的标题,我深表歉意,我想不出这个问题的正确措辞。相反,我只会给你背景信息和目标: 这是在一个表中,一个人可能有也可能没有多行数据,这些行可能包含相同的 activity_id 值,也可
具有 3 列的数据库表 - A int , B int , C int 我的问题是: 如何使用 Sequelize 结果找到 A > B + C const countTasks = await Ta
我在通过以下功能编写此查询时遇到问题: 首先按第 2 列 DESC 排序,然后从“不同的第 1 列”中选择 只有 Column1 是 DISTINCT 此查询没有帮助,因为它首先从第 1 列中进行选择
使用 Bootstrap 非常有趣和有帮助,目前我在创建以下需求时遇到问题。 “使用 bootstrap 在桌面上有 4 列,在平板电脑上有 2 列,在移动设备上有 1 列”谁能告诉我正确的结构 最佳
我是 R 新手,正在问一个非常基本的问题。当然,我在尝试从所提供的示例中获取指导的同时做了功课here和 here ,但无法在我的案例中实现这个想法,即可能是由于我的问题中的比较维度更大。 我的实
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个 df , delta1 delta2 0 -1 2 0 -1 0 0 0 我想知道如何分配 delt
您好,我想知道是否可以执行以下操作。显然,我已经尝试在 phpMyAdmin 中运行它,但出现错误。也许还有另一种方式来编写此查询。 SELECT * FROM eat_eat_restaurants
我有 2 个列表(标题和数据值)。我想要将数据值列 1 匹配并替换为头文件列 1,以获得与 dataValue 列 1 和标题值列 2 匹配的值 头文件 TotalLoad,M0001001 Hois
我有两个不同长度的文件,file2 是一个很大的引用文件,我从中提取文件 1 的数据。 我有一行 awk,我通常会对其进行调整以在我的文件中进行查找和替换,但它总是在同一列中进行查找和替换。 所以对于
假设我有两个表,如下所示。 create table contract( c_ID number(1) primary key, c_name varchar2(50) not
我有一个带有 varchar 列的 H2 表,其检查约束定义如下: CONSTRAINT my_constraint CHECK (varchar_field <> '') 以下插入语句失败,但当我删
这是最少量的代码,可以清楚地说明我的问题: One Two Three 前 2 个 div 应该是 2 个左列。第三个应该占据页面的其余部分。最后,我将添加选项来隐藏和
在 Azure 中的 Log Analytics 中,我为 VM Heartbeat 选择一个预定义查询,我在编辑器中运行查询正常,但当我去创建警报时,我不断收到警报“查询未返回 TimeGenera
在 Azure 中的 Log Analytics 中,我为 VM Heartbeat 选择一个预定义查询,我在编辑器中运行查询正常,但当我去创建警报时,我不断收到警报“查询未返回 TimeGenera
今天我开始使用 JexcelApi 并遇到了这个:当您尝试从特定位置获取元素时,不是像您通常期望的那样使用sheet.getCell(row,col),而是使用sheet.getCell(col,ro
我有一个包含 28 列的数据库。第一列是代码,第二列是名称,其余是值。 public void displayData() { con.Open(); MySqlDataAdapter
我很沮丧:每当我缩小这个网页时,一切都变得一团糟。我如何将网页居中,以便我可以缩小并且元素不会被错误定位。 (它应该是 2 列,但所有内容都合并为 1)我试过 但由于某种原因,这不起作用。 www.o
我是一名优秀的程序员,十分优秀!