Welcome To Uday Satya Blog

49 - 51 PROGRAMS



/******************************************
    49.To find the sum of 2 matrices
 ***************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j,k;
int arr1[3][3],arr2[3][3],arr3[3][3];

printf("Enter the elements to the first matrix ");

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

printf("Enter the elements to the second matrix ");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  scanf("%d",&arr2[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr3[i][j]=(arr1[i][j]+arr2[i][j]);
   }
  }
 printf("The sum is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr3[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the first matrix 1 2 3 4 5 6 7 8 9
Enter the elements to the second matrix 10 10 10 10 10 10 10 10 10
The sum is
11      12      13
14      15      16
17      18      19

/* *********************************************
     50.To find the product of 2 matrices
   ********************************************* */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j,k,l;
int arr1[3][3],arr2[3][3],arr3[3][3];

printf("Enter the elements to the first matrix ");

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

printf("Enter the elements to the second matrix ");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  scanf("%d",&arr2[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr3[i][j]=0;
   for(k=0;k<3;k++)
   {arr3[i][j]+=(arr1[i][k]*arr2[k][j]);
   }
  }
 }
 printf("The product is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr3[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the first matrix 1 2 3 4 5 6 7 8 9
Enter the elements to the second matrix 1 0 0 0 1 0 0 0 1
The product is
1       2       3
4       5       6
7       8       9

/* **************************************************** 
         51.To find the transpose of a matrix
   **************************************************** */
#include<*stdio.h>
#include*
void main()
{
clrscr();
int i,j;
int arr1[3][3],arr2[3][3];

printf("Enter the elements to the matrix ");

for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr2[j][i]=arr1[i][j];
   }
  }
 printf("The transpose is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr2[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the matrix 1 2 3 4 5 6 7 8 9
The transpose is
1       4       7
2       5       8
3       6       9

0 comments:

Post a Comment