Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

multiplication

#include <stdio.h>

void main()
{
    int r1,r2,c1,c2,a[10][10],b[10][10],c[10][10],i,j,k;
    printf("Enter the no. of rows and columns of 1st matrix:\n");
    scanf("%d%d",&r1,&c1);
    printf("Enter the no. of rows and columns of 2nd matrix:\n");
    scanf("%d%d",&r2,&c2);
    if(c1==r2)
    {
        printf("Enter elements of 1st matrix:");
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c1;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        printf("Enter elements of 2nd matrix:");
        for(i=0;i<r2;i++)
        {
            for(j=0;j<c2;j++)
            {
                scanf("%d",&b[i][j]);
            }
        }
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                c[i][j]=0;
                for(k=0;k<r1;k++)
                {
                    c[i][j]+=a[i][k]*b[k][j];
                }
            }
        }
        printf("Product of a and b\n");
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                printf("%d",c[i][j]);
            }
            printf("\n");
        }
    }
    else
    printf("Invalid input");
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.