0

Matrix product

İs there someone to recover my matrix product code ? for(int i=0; i<satir; i++){           for(int j=0; j<sutun2; j++){             for(int k=0; k<sutun1; k++){                 toplam += dizi1[i][k] * dizi2[k][j];             }             diziCarp[i][j] = toplam;              toplam = 0;               printf("%d ", diziCarp[i][j]);          }         printf("\n");     }     printf("\n");          return 0;    

13th Dec 2018, 10:01 AM
Nurullah Aydın
Nurullah Aydın - avatar
3 ответов
+ 3
#include <stdio.h> #include <time.h> #include <stdlib.h> int rng() { return 1 + rand() % 5; } void filler(size_t, size_t, int [*][*]); int main() { srand(time(NULL)); int dizi1[4][4], dizi2[4][5], diziCarp[4][5]; size_t satir = 4, sutun2 = 5, sutun1 = 4; int toplam = 0; printf("Mat A:\n"); filler(4, 4, dizi1); printf("\nMat B:\n"); filler(4, 5, dizi2); printf("\nA . B:\n"); for(int i = 0; i < satir; i++){ for(int j = 0; j < sutun2; j++){ for(int k = 0; k < sutun1; k++){ toplam += dizi1[i][k] * dizi2[k][j]; } diziCarp[i][j] = toplam; toplam = 0; printf("%d ", diziCarp[i][j]); } printf("\n"); } printf("\n"); } void filler(size_t m, size_t n, int arr[m][n]) { for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { arr[i][j] = rng(); printf("%d ", arr[i][j]); } printf("\n"); } } Sample Output: Mat A: 4 3 2 3 4 5 3 3 3 1 1 1 1 1 5 5 Mat B: 5 3 1 5 4 1 5 3 5 3 3 4 5 2 5 5 2 3 2 5 A . B: 44 41 32 45 50 49 55 43 57 61 24 20 14 24 25 46 38 44 30 57
13th Dec 2018, 11:13 AM
Babak
Babak - avatar
+ 1
Thank youu 👍
14th Dec 2018, 12:26 AM
Nurullah Aydın
Nurullah Aydın - avatar
0
When I try to product 4×4 matrix and 4×5 matrix, it doesn't work correctly
13th Dec 2018, 10:04 AM
Nurullah Aydın
Nurullah Aydın - avatar