函式_兩矩陣相加

 avatar
user_3763047219
c_cpp
2 years ago
774 B
0
Indexable
Never
void plusm(int a[3][3], int b[3][3], int c[3][3]);


void plusm(int a[3][3], int b[3][3], int c[3][3]) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            c[i][j] = a[i][j] + b[i][j];
        }
    }
}

#include <stdio.h>
#include <stdlib.h>


int main() {
    int a[3][3], b[3][3], c[3][3], i, j;
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            scanf("%d", &b[i][j]);
        }
    }

    plusm(a, b, c);

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            printf("%d ", c[i][j]);
        }
        printf("\n");
    }
    return 0;
}