Monday 5 November 2018

LESSON 5 Product of two matrix C Programming

Product of two matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,p,q,i,j,k,a[20][20],b[20][20],c[20][20];
clrscr();
printf("enter the no of rows & columnsof matrix 1\n");
scanf("%d%d",&m,&n);
if(m==0||n==0)
{
printf("matrix is not possible");
}
printf("enter the array elements\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the no of rows & columnsof matrix 2\n");
scanf("%d%d",&p,&q);
if(p==0||q==0)
{
printf("matrix is not possible");
}
printf("enter the array elements\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("the  matrix 1 is \n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\n\n");
}
printf("the  matrix 2 is \n\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n\n\n");
}
printf("\n");
if(n==p)
printf("multiplication is possible\n");
else
{
printf("multiplication is not possible");
exit(0);
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
printf("product is\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n\n\n");
}
getch();
}

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes