Array multiolication in Two-Dimensional Array using Array in C


This program is about multiply and print the element in a two dimensional matrix using array.

Source Code

#include<stdio.h>
int main()
{
  int a[5][5],b[5][5],m[5][5];
  int i,j,r,c,t,k;
  printf("\nEnter No of Rows : ");
  scanf("%d",&r);
  printf("\nEnter No of Columns : ");
  scanf("%d",&c);
  printf("\nEnter A Matrix : ");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
        printf("\t%d",a[i][j]);
    }
    printf("\n");
  }
  printf("\nEnter B Matrix : ");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       scanf("%d",&b[i][j]);
    }
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       printf("\t%d",b[i][j]);
    }
    printf("\n");
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
      t=0;
      for(k=0;k<c;k++)
      {
         t+=(a[i][k]*b[k][j]);
      }
      m[i][j]=t;
    }
  }
  printf("\nResult Matrix : \n");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       printf("\t%d",m[i][j]);
    }
    printf("\n");
  }
  return 0;
}
To download raw file Click Here

Output

Enter No of Rows : 2
Enter No of Columns : 2
Enter A Matrix : 2
3
4
5

2	3
4	5

Enter B Matrix : 5
6
7
8

5	6
7	8

Result Matrix : 
	31	36
	55	64


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes