Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int mat[10][10];
- int mat2[10][10];
- int summa[10][10];
- int x, y;
- FILE *luku;
- FILE *luku2;
- FILE *kirj_tied;
- if ((luku = fopen("mata.txt", "r")) == NULL) {
- printf("Tiedoston avaus epäonnistui!");
- } else {
- for (y = 0; y < 10; y++) {
- fscanf(luku, "\n");
- for (x = 0; x < 10; x++) {
- mat[y][x] = 0;
- if (x == 9) {
- fscanf(luku, "%d", &mat[y][x]);
- } else {
- fscanf(luku, "%d ", &mat[y][x]);
- }
- }
- }
- }
- fclose(luku);
- if ((luku2 = fopen("matb.txt", "r")) == NULL) {
- printf("Tiedoston avaus epäonnistui!");
- } else {
- for (y = 0; y < 10; y++) {
- for (x = 0; x < 10; x++) {
- mat2[y][x] = 0;
- if (x == 9) {
- fscanf(luku2, "%d", &mat2[y][x]);
- } else {
- fscanf(luku2, "%d ", &mat2[y][x]);
- }
- }
- }
- }
- fclose(luku2);
- for (y = 0; y < 10; y++) {
- for (x = 0; x < 10; x++) {
- summa[y][x] = mat[y][x] + mat2[y][x];
- }
- }
- if ((kirj_tied = fopen("summa.usr", "w")) == NULL) {
- printf("Tiedoston luku epäonnistui!");
- } else {
- for (y = 0; y < 10; y++) {
- for (x = 0; x < 10; x++) {
- if (x == 9) {
- fprintf(kirj_tied, "%d\n", summa[y][x]);
- } else {
- fprintf(kirj_tied, "%d ", summa[y][x]);
- }
- }
- }
- printf("Matriisien summa on laskettu tiedostoon summa.usr.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement