C语言数组练习题

C语言数组练习题_第1张图片
1022e5f26e0926e0edef42e834a18714.jpg
C语言数组练习题_第2张图片
Paste_Image.png

include

int main()
{
int a[5][5], i, j;
for (i = 0; i < 5; ++i)
{
printf("Enter row %d: ", i+1);
for (j = 0; j < 5; ++j)
{
scanf("%d", &a[i][j]);
}
}
int sumrow = 0, i2, j2;

printf("Row totals: ");
for (i2 = 0; i2 < 5; ++i2)
{
    for (j2 = 0; j2 < 5; ++j2)
    {
        sumrow = sumrow + a[i2][j2];
    }
    printf("%d ", sumrow);
    sumrow = 0;
}
printf("\n");

printf("Column totals: ");
int sumcolumn = 0, i3, j3;
for (j3 = 0; j3 < 5; ++j3)
{
    for (i3 = 0; i3 < 5; ++i3)
    {
        sumcolumn += a[i3][j3];
    }
    printf("%d ", sumcolumn);
    sumcolumn = 0;
}

return 0;

}

实现结果:

C语言数组练习题_第3张图片
Paste_Image.png

Note:
for (int i = 0, i < count, ++i)
这种在for函数内定义变量的用法只有C99中可用。gcc默认为C89,编译失败。

你可能感兴趣的:(C语言数组练习题)