matrix multiplication

#include<stdio.h>
int multiply(int x[20][20],int y[20][20],int ,int ,int );

int main()
{
    int x[20][20],y[20][20];
    int i,j,k,m,n,p;

    printf("Enter the number of rows and columns for the 1st matrix :- \n");
    scanf("%d%d",&m,&n);

    printf("Enter the elements of the 1st matrix :- \n");

    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&x[i][j]);
        }
    }

    printf("Enter the number of columns for 2nd matrix\n");
    scanf("%d",&p);

    printf("Enter the elements of the 2nd matrix\n");
    for(i=0; i<n; i++)
    {
        for(j=0; j<p; j++)
        {
            scanf("%d",&y[i][j]);
        }
    }

    printf("The 1st matrix is :-\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%d\t",x[i][j]);
        }
        printf("\n");
    }
    printf("The 2nd matrix is :-\n");
    for(i=0;i<n;i++)
    {
        for(j=0;j<p;j++)
        {
            printf("%d\t",y[i][j]);
        }
        printf("\n");
    }
    multiply(x,y,m,n,p);
}

int multiply(int x[20][20],int y[20][20],int m,int n,int p)
{
    int mul[20][20],i,j,k;

    for(i=0;i<m;i++)
    {
        for(j=0;j<p;j++)
        {
            mul[i][j]=0;

            for(k=0;k<n;k++)
            {
                mul[i][j]=mul[i][j]+x[i][k]*y[k][j];
            }
        }
    }

    printf("The resultant matrix derived : \n");

    for(i=0;i<m;i++)
    {
        for(j=0;j<p;j++)
        {
            printf("%d\t",mul[i][j]);
        }
        printf("\n");
    }
}


OUTPUT : -







For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-

For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments