有没有人会大一c语言的呀qaq

img

这个是大一c语言的题 实在是不会了 有没有人可以给讲一下啊 qaq qaq

相同大小的矩阵相加,用嵌套的for循环遍历矩阵里面每一个数,相同下标的数相加。示例程序如下:

#include <stdio.h>

#define MAX_SIZE 10

void readMatrix(int matrix[MAX_SIZE][MAX_SIZE], int rows, int columns) {
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }
}

void sumMatrices(int sum[MAX_SIZE][MAX_SIZE], int matrixA[MAX_SIZE][MAX_SIZE], int matrixB[MAX_SIZE][MAX_SIZE], int matrixC[MAX_SIZE][MAX_SIZE], int rows, int columns) {
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            sum[i][j] = matrixA[i][j] + matrixB[i][j] + matrixC[i][j];
        }
    }
}

void printMatrix(int matrix[MAX_SIZE][MAX_SIZE], int rows, int columns) {
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}

int main() {
    int matrixA[MAX_SIZE][MAX_SIZE], matrixB[MAX_SIZE][MAX_SIZE], matrixC[MAX_SIZE][MAX_SIZE], sum[MAX_SIZE][MAX_SIZE];
    int rows, columns;

    printf("Enter the number of rows and columns for the matrices: ");
    scanf("%d %d", &rows, &columns);

    printf("Enter elements for matrix A:\n");
    readMatrix(matrixA, rows, columns);

    printf("Enter elements for matrix B:\n");
    readMatrix(matrixB, rows, columns);

    printf("Enter elements for matrix C:\n");
    readMatrix(matrixC, rows, columns);

    sumMatrices(sum, matrixA, matrixB, matrixC, rows, columns);

    printf("Sum of the matrices [A]+[B]+[C] is:\n");
    printMatrix(sum, rows, columns);

    return 0;
}