Print user define multiplication of two matrix | C-program


 Multiplication of matrix:

Code:

#include<stdio.h>

void main()

{

    int a[10][10],b[10][10],c[10][10],i,j,k,n,m,p,q,sum;

    printf("Enter the size of lst matrix [10][10]:\n");

    scanf("%d%d",&m,&n);

    printf("Enter the elements of 2nd matrix [10][10]:\n");

    scanf("%d%d",&p,&q);

    if(n==p)

    {

        printf("Matrix is possible!\n");

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

        for(i=0;i<m;i++)

        {

            for(j=0;j<n;j++)

                scanf("%d",&a[i][j]);

        }

        printf("Enter elements of 2nd matrix:\n");

        for(i=0;i<p;i++)

        {

            for(j=0;j<q;j++)

                scanf("%d",&b[i][j]);

        }

        for(i=0;i<m;i++)

        {

            for(j=0;j<q;j++)

            {

                sum=0;

                for(k=0;k<n;k++)

                    sum+=a[i][k]*b[k][j];

                c[i][j]=sum;

            }

        }

        printf("The matrix is:\n");

        for(i=0;i<m;i++)

        {

            for(j=0;j<q;j++)

                printf("%d\t",c[i][j]);

            printf("\n");

        }

    }

    else

        printf("Matrix not possible");

}

Output:

 

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :