Welcome To Uday Satya Blog

06 - 11 PROGRAMS


/* ****************************************************
 6.TO TAKE DIMENSIONS OF MATRIX & SUBSTRACT    *************************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],I,j,m,n,p,q;
clrscr();
printf(“\n enter the dimensions of matrix ‘A’ : “);
scanf(“%d %d”,&m,&n);
printf(“\n enter the dimensions of matrix ‘B’ : “);
scanf(“%d %d”,&p,&q);
if((m==p)&&(n==q))
{
printf(“\n matrix substraction is possible”);
printf(“\n”);
printf(“\n enter the elements into the matrix ‘A’ : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n enter the elements into the matrix ‘B’ : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
printf(“\n the sum of two matrices ‘A’ and ‘B’ is : “);
printf(“\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”,c[i][j]);
}
printf(“\n”);
}
}
else
{
printf(“\n matrix substraction is not possible”);
}
getch();
}

 output

 enter the dimensions of matrix ‘A’ : 3 3

 enter the dimensions of matrix ‘B’ : 3 3

 matrix substraction is possible

 enter the elements into the matrix ‘A’ : 1 1 1 1 1 1 1 1 1

 enter the elements into the matrix ‘B’ : 1 1 1 1 1 1 1 1 1

 the sum of two matrices ‘A’ and ‘B’ is :
         0       0       0
         0       0       0
         0       0       0

enter the dimensions of matrix ‘A’ : 2 3

 enter the dimensions of matrix ‘B’ : 3 2

 matrix substraction is not possible
/* ***************************************************
   7.TO TAKE DIMENSIONS OF MATRIX & MULTIPLY    ************************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,m,n,p,q;
clrscr();
printf("\n enter the dimensions of matrix 'A' : ");
scanf("%d %d",&m,&n);
printf("\n enter the dimensions of matrix 'B' : ");
scanf("%d %d",&p,&q);
if((n==p)&&(m==q))
{
printf("\n matrix multiplication is possible");
printf("\n");
printf("\n enter the elements into the matrix 'A' : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n enter the elements into the matrix 'B' : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
c[i][j]=c[i][j]+(a[i][j]*b[j][i]);
}
}
printf("\n the product of two matrices 'A' and 'B' is : ");
printf("\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n");
}
}
else
{
printf("\n matrix multiplication is not possible");
}
getch();
}
output

 enter the dimensions of matrix 'A' : 3 3

 enter the dimensions of matrix 'B' : 3 3

 matrix multiplication is possible

 enter the elements into the matrix 'A' : 1 1 1 1 1 1 1 1 1

 enter the elements into the matrix 'B' : 1 1 1 1 1 1 1 1 1

 the product of two matrices 'A' and 'B' is :
         1       1       1
         1       1       1
         1       1       1

 enter the dimensions of matrix 'A' : 2 2

 enter the dimensions of matrix 'B' : 3 3

  matrix multiplication is not possible
/* ***************************************************
     8 .TO FIND THE TRACE OF THE GIVEN MATRIX .
   *************************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],i,j,sum=0;
clrscr();
printf(“\n enter the elements into the matrix ‘A’ : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
{
sum=sum+a[i][j];
}
}
}
printf(“\n the trace of the matrix is : %d “,sum);
getch();
}

output

 enter the elements into the matrix ‘A’ : 1 1 1 1 1 1 1 1 1

 the trace of the matrix is : 3
/* *************************************************
      9 .TO FIND  TRANSPOSE OF  GIVEN MATRIX.
   ************************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf(“\n enter the elements into the matrix : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n the matrix is : “);
printf(“\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”,a[j][i]);
}
printf(“\n”);
}
getch();
}

output

 enter the elements into the matrix : 1 2 3 1 2 3 1 2 3

 the matrix is :
         1       1       1
         2       2       2
         3       3       3

/* ***************************************************
   10 .TO FIND UPPER TRIANGULAR OF GIVEN MATRIX.
   ************************************************ */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf(“\n enter the elements into the matrix : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n the upper triangular matrix is  : “);
printf(“\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i<=j)
{
printf(“\t %d”,a[i][j]);
}
}
}
getch();
}

output

 enter the elements into the matrix : 1 2 3 4 5 6 7 8 9

 the upper triangular matrix is  :

       1       2        3       5       6       9       


/* **************************************************
      11. TO FIND LOWER TRIANGLE OF GIVEN MATRIX .
    ************************************************* */
#include<*stdio.h>
#include<*conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf(“\n enter the elements into the matrix ‘A’ : “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n the lower triangular of matrix ‘A’ is : “);
printf(“\n\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i>=j)
{
printf(“\t%d”,a[i][j]);
}
}
}
getch();
}

output

 enter the elements into the matrix ‘A’ : 1 2 3 4 5 6 7 8 9

 the lower triangular of matrix ‘A’ is :
    
        1       4       5       7       8       9
     

0 comments:

Post a Comment