Anda di halaman 1dari 10

# /*Program to Display Transpose of a Matrix using one Array!

*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10];
int i,j,order,temp;
printf("Enter order of the square matrix : ");
scanf("%d",&order);
printf("\nEnter Elmements of the matrix :");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
... {
printf("\nEnter Element [%d][%d] : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("Matrix : \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<order;i++)
{
for(j=i;j<order;j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
printf("\nTranspose : \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
getch();
}

second

## /*Program to find trace of a matrix*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10];
int i,j,order,sum=0;
printf("Enter order of Matrix : ");
scanf("%d",&order);
printf("\nEnter elements of the matrix \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("Enter eleme...nt [%d][%d] : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\nMatrix : \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<order;i++)
{
sum=sum+a[i][i];
}
printf("\nTrace : %d",sum);
getch();
}
thrid one

## /*Program to Display the Transpose of a Matrix using two arrays*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10],b[10][10];;
int i,j,order,temp;
printf("Enter order of the square matrix : ");
scanf("%d",&order);
printf("\nEnter Elmements of the matrix :");
for(i=0;i<order;i++)
{
for(j=0;j<ord...er;j++)
{
printf("\nEnter Element [%d][%d] : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("Matrix : \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<order;i++)
{
for(j=i;j<order;j++)
{
a[i][j]=b[j][i];
}
}
printf("\nTranspose : \n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
getch();
}
Subtraction
/*Program to subtract two matrices*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10],b[10][10],diff[10][10];
int row,clm,i,j;
printf("Enter order of matrix (row,coloumn) :");
scanf("%d%d",&row,&clm);
printf("\nEnter %d elements of Matrix A ->\n",row*clm);
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++...)
{
printf("\nEnter element [%d][%d] : ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nEnter %d elements of Matrix B ->\n");
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++)
{
printf("\nEnter element [%d][%d] : ",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\nMatrix A ->\n");
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\nMatrix B ->\n");
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++)
{
printf(" %d ",b[i][j]);
}
printf("\n");
}
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++)
{
diff[i][j]=a[i][j]-b[i][j];
}
}
printf("\nDifference of the Matrices :\n");
for(i=0;i<row;i++)
{
for(j=0;j<clm;j++)
{
printf(" %d ",diff[i][j]);
}
printf("\n");
}
getch();
}
lower Triangle
/*Program to display lower triangle of a matrix*/

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10];
int i,j,sp,order;
printf("Enter order of Matrix :");
scanf("%d",&order);
printf("\nEnter Elements ->\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("\nEnter Element... [%d][%d] : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\nMatrix ->\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\nLower Triangle :\n");
for(i=0;i<order;i++)
{
for(j=0;j<=i;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
getch();
}
Upper triangle
#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10];
int i,j,sp,order;
printf("Enter order of Matrix :");
scanf("%d",&order);
printf("\nEnter Elements ->\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf("\nEnter Element... [%d][%d] : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\nMatrix ->\n");
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
printf("\nUpper Triangle :\n");
for(i=0;i<order;i++)
{
for(sp=0;sp<i;sp++)
{
printf(" ");
}
for(j=i;j<order;j++)
{
printf(" %d ",a[i][j]);
}
printf("\n");
}
getch();
}