Custom Search

Monday 12 December 2011

Q7)Write a program to fing the product of 2 matrices


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>

void main()
{
 clrscr();
 int m1[25][25],m2[25][25],m[25][25],r1,c1,r2,c2,i,j,k;
 printf("\nenter the order of first matrix : ");
 scanf("%d %d",&r1,&c1);
 printf("\nenter the order of second matrix : ");
 scanf("%d %d",&r2,&c2);
 if(r2==c1)
 {
  printf("\nenter the elements of first matrix : ");
  for(i=0;i
  {
   for(j=0;j
   {
    scanf("%d",&m1[i][j]);
   }
  }
  printf("\nenter the elements of second matrix : ");
  for(i=0;i
  {
   for(j=0;j
   {
    scanf("%d",&m2[i][j]);
   }
  }
  printf("\n\nfirst matrix : \n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m1[i][j]);
   }
   printf("\n");
  }
  printf("\nsecond matrix : \n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m2[i][j]);
   }
   printf("\n");
  }
  for(i=0;i
  {
   for(j=0;j
   {
    m[i][j]=0;
    for(k=0;k
     m[i][j]=m[i][j]+(m1[i][k]*m2[k][j]);
    }
  }
  printf("\nproduct of two matrices :\n");
  for(i=0;i
  {
   for(j=0;j
   {
    printf(" %d ",m[i][j]);
    printf(" ");
   }

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...