#include int main(void) { FILE *opena; FILE *openb; FILE *write_sum; int mata[10][10], matb[10][10], sum[10][10]; /*mata.txt*/ opena = fopen("mata.txt", "r"); if (opena == NULL) { printf("Failed to read mata.txt"); return 0; } else { for (int i=0; i<10; i++) { for (int j=0; j<10; j++) { if (j==9) { fscanf(opena, "%d\n", &mata[i][j]); } else { fscanf(opena, "%d ", &mata[i][j]); } } } } fclose(opena); /*matb.txt*/ openb = fopen("matb.txt", "r"); if (openb == NULL) { printf("Failed to read matb.txt"); return 0; } else { for (int i=0; i<10; i++) { for (int j=0; j<10; j++) { if (j==9) { fscanf(opena, "%d\n", &matb[i][j]); } else { fscanf(opena, "%d ", &matb[i][j]); } } } } fclose(openb); /*sum of mata and matb*/ for (int i=0; i<10; i++) { for (int j=0; j<10; j++) { sum[i][j] = mata[i][j] + matb[i][j]; } } /*write sum.usr*/ write_sum = fopen("sum.usr", "w"); if (write_sum == NULL) { printf("Failed to write sum.usr"); return 0; } else { for (int i=0; i<10; i++) { for (int j=0; j<10; j++) { if (j==9) { fprintf(write_sum, "%d\n", sum[i][j]); } else { fprintf(write_sum, "%d ", sum[i][j]); } } } printf("The sum of the matrices has been calculated into the file sum.usr."); } fclose(write_sum); }