C++의 행렬 미적분학 - 두 행렬 곱하기

C++에서 두 행렬의 곱셈


#include< stdio.h> 
#include< stdlib.h입니다>
#include < iostream입니다>
using 네임스페이스 std;
typedef 구조체 matrix
{
int 줄;
int 열;
int** 데이터;
}행렬;
struct 행렬 creer_matrice(int 행, int 열){
구조체 행렬 m;
m.row = 행;
m.column = 열;
m.data = (int**)malloc(m.line*sizeof(int *));
for(int i = 0; i< m.row; ++i){
// calloc
m.data[i] = (int *)calloc(m.column,sizeof(int));
}
return m;
}

void afficher_matrice(matrix M){
for(int i = 0; i < M.라인; i++) {
for(int j = 0; j < M.colonne; j++) {
비용 < < M.데이터[i][j] ;
비용 < < "\t";
}
//줄 바꿈
비용 < < "\n";
}
비용 < < "\n";
}

struct 곱 행렬(행렬 A, 행렬 B)
{
행렬 C = creer_matrice(A.row, B.column);
for(int I = 0; 나는 < A.라인; I++)
for(int J = 0; J < B.열; J++)
{
C.data[I][J] = 0;
for(int K = 0; 케이 < A. 열; K++)
{
C.data[I][J] += A.data[I][K] * B.data[K][J];
}
}
반환 C;
}

int main(int argc, char *argv[])
{
/*
행렬 A
*/
행렬 A = creer_matrice(4,3);
srand(시간(NULL));
for(int i=0; i< A.라인; i++)
for(int j=0; j< A. 열; j++)
//0에서 20 사이의 난수를 생성하고 10을 뺍니다
//음수를 얻으려면
//예: rand가 74를 생성하면 74-100 = -36
A.data[i][j] =rand()%20-10;
afficher_matrice(A);

/*
두 번째 행렬
*/
행렬 B = creer_matrice(3.5);
srand(시간(NULL));
for(int i=0; i< B.라인; i++)
for(int j=0; j< B.열; j++)
//0에서 20 사이의 난수를 생성하고 10을 뺍니다
//음수를 얻으려면
//예: rand가 74를 생성하면 74-100 = -36
B.data[i][j] =rand()%20-10;
afficher_matrice(B)입니다.

//product
//행렬 C = product(A,B);
//afficher_matrice(C);
afficher_matrice(전원(A));
시스템("일시 중지");
}