'C-matrix multiplication

I was writing an code for matrix multiplication in C. I am not getting the desired output. I tried using functions for different parts of code but there seems to be some problem. Kindly explain? Is Function not returning the value of Arrays or is it something else? Should I use concept of pointers here?

#include<stdio.h>

// MATRIX MULTIPLICATION

// Function to take elements
void GetElements(int row, int col, int A[100][100]){
    for(int i=0;i<row;i++){
        for(int j=0;j<col;j++){
            printf("Element%d%d:-",i+1,j+1);
            scanf("%d",&A[i][j]);
        }
    }
}

void MatrixMultiplication(int row,int col, int row_col,int A[100][100],int B[100][100],int Result[100][100]){
    for(int i=0;i<row;i++){
        for(int j=0;j<col;j++){
            for(int k=0;k<row;k++){
                Result[row][col] += A[row][row_col]*B[row_col][col];
            }
        }
    }
}

void display(int Result[100][100],int row, int col){
    for(int i=0;i<row;i++){
        for(int j=0;j<col;j++){
            printf("%d ",Result[row][col]);
            if(j==col-1) printf("\n");
        }
    }
}

void main(){
    int A[100][100],B[100][100],Result[100][100],a_col,a_row,b_row,b_col;

    printf("Enter Rows of Matrix A:-");
    scanf("%d",&a_row);
    printf("Enter Columns of Matrix A:-");
    scanf("%d",&a_col);
    printf("Enter Rows of Matrix B:-");
    scanf("%d",&b_row);
    printf("Enter Columns of Matrix B:-");
    scanf("%d",&b_col);

    while(a_col != b_row){  // Making sure that Condition of Matrix Multiplication Satisifies
        printf("Error!!!\nNumbers of Columns of A should be equal to Number of Rows of B\n");
        printf("Enter Rows of Matrix A:-");
        scanf("%d",&a_row);
        printf("Enter Columns of Matrix A:-");
        scanf("%d",&a_col);
        printf("Enter Rows of Matrix B:-");
        scanf("%d",&b_row);
        printf("Enter Columns of Matrix B:-");
        scanf("%d",&b_col);
    }
    
    // Getting Elements for A and B
    printf("Enter Elements for A\n");
    GetElements(a_row,a_col,A);
    printf("Enter Elements for B\n");
    GetElements(b_row,b_col,B);

    MatrixMultiplication(a_row,b_col,b_row,A,B,Result);
    display(Result,a_row,b_col);
}

Output:

OUTPUT



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source