Wednesday, 5 December 2012

CPL PROGRAM 15 CODING

                             
                       MATRIX MULTIPLICATION USING FUNCTION
                                             
CODING:                                                    
                                            
#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10][10],i,j,k,b[10][10],c[10][10],r1,c1,r2,c2;
    printf("Enter number of rows and columns of first matrix \n");
    scanf("%d %d",&r1,&c1);
    printf("Enter number of rows and columns of second matrix \n");
    scanf("%d %d",&r2,&c2);
    if(r2==c1)
    {
        printf("Enter rows and columns of First matrix \n");
        for(i=0;i<r1;i++)
        {
         for(j=0;j<c1;j++)
         {
      scanf("%d",&a[i][j]);
     }
    }
   
    printf("Enter rows and columns of Second matrix \n");
    for(i=0;i<r2;i++)
    {
     for(j=0;j<c2;j++)
     {
      scanf("%d",&b[i][j]);
     }
    }
   
    printf("Multiplication of the Matrices:\n");
    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("%d\t",c[i][j]);
     }
     printf("\n");
       }
    }
    else
    printf("Matrix multiplication cannot be done");
getch();
}

No comments:

Post a Comment