C++ programs 01 FOR MECHANICAL

1. The multiplication of two matrices Amxn and Bnxk.
# include <stdio.h>
# define MAXR 10
# define MAXC 10
main()
{
  int r1,c1, r2, c2, i, j, k;
  float mat1[MAXR][MAXC], mat2[MAXR][MAXC],pro[MAXR][MAXC];
  printf("Dimension of Matrix 1\n");
  scanf("%d%d", &r1, & c1);
  printf("Dimension of Matrix 2\n");
  scanf("%d%d", &r2, & c2);
if (c1==r2)
 {
  printf (" Enter the values of Mat1 row-wise\n");
  for (i=1; i<=r1; i++)
  {
  for (j=1; j<=c1; j++)
  {
   scanf("%f",& mat1[i][j]);
  } }
  printf("Enter the values of Mat 2 row-wise\n");
  for (i=1; i<= r2;i++)
  {
   for (j=1; j<=c2; j++)
   {
    scanf("%f",& mat2[i][j]);
   }
  }
  for (i=1; i<=r1; i++)
  {
   for (j=1; j<=c2; j++)
  {
   pro[i][j]=0.0;
  for(k=1; k<=c1; k++)
  {
   pro[i][j]= pro[i][j]+ mat1[i][k]* mat2[k][j];
  }
  }
  }
  printf("Product Matrix:\n\n");
  for(i=1; i<=r1; i++)
  {
   printf("\n");
  for (j=1; j<=c2; j++)
  {
  printf("%9.3f",pro[i][j]);
  } } }
 else
  { printf("INCORRECT");
  }
  return 0;

Comments

Popular posts from this blog

Industrial Attachment

লেনজ এর সুত্র