C Program to multiply two matrices

 #include<stdio.h>

#include<stdlib.h>


int main()

{

int rows1, columns1, rows2, columns2, matrix1[50][50],matrix2[50][50],matrix3[50][50],sum=0;

printf("------------------Programme to find the multiplication of a matrix:----------------------\n");

printf("Enter no.  of rows of first matrix:\n");

scanf("%d",&rows1);

printf("Enter no. of columns of first matrix:\n");

scanf("%d",&columns1);

printf("Enter the element of first matrix:\n");

int i,j;

for(i=0; i<rows1; i++)

{

for(j=0; j<columns1; j++)

{

printf("Element::[%d,%d]",i,j);

scanf("%d",&matrix1[i][j]);

}

}

printf("Enter no.  of rows of second matrix:\n");

scanf("%d",&rows2);

printf("Enter no. of columns of second matrix:\n");

scanf("%d",&columns2);

if(rows1==columns2)

{

printf("Enter the element of second matrix:\n");

for(i=0; i<rows2; i++)

{

for(j=0; j<columns2; j++)

{

printf("Element::[%d,%d]",i,j);

scanf("%d",&matrix2[i][j]);

}

}

  }

  else

  {

   printf("Please enter a matrix of equal order:\n");

  }

  

int m,n,o;

    for ( m= 0 ; m< rows1; m++ )

    {

      for ( n= 0 ; n< columns2 ; n++ )

      {

        for ( o = 0 ; o <rows2;o++ )

        {

          sum = sum + matrix1[m][o]*matrix2[o][n];

        }

 

        matrix3[m][n] =sum;

        sum = 0;

      }

    }

printf("Answer:\n");

for(i=0;i<rows1;i++)

{

for(j=0;j<columns2;j++)

{

printf("[%3d] ",matrix3[i][j]);

}

printf("\n");

}

return 0;


OUTPUT:



}


Comments

Popular posts from this blog

[ C++ program] Assume that a bank maintains two kinds of accounts for customers, | | one called as savings account and the other as current account. | | The savings account provides compound interest and withdrawal facilities but no cheque book facility. | | The current account provides cheque book facility but no interest. | | Current account holders should also maintain a minimum balance | | and if the balance falls below this level, a service charge is imposed. | | Create a class account that stores customer name, account number and type of account. | | From this derive the classes curacct and savacct to make them more specific to their requirements.

Write a program in C++ to create a base class shape and derive two classes named Circle and Square from it. Create and initialize objects from these classes using appropriate constructors.

Write a program to search an element using Binary Search.