Matrix product | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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