Friday, October 14, 2011

Write a C program to find a. Addition of two matrices b. Multiplication of two matrices. c. Trace of a matrix d. Transpose of matrix

#include
main()
{
printf("\t\t1.Addition of two matrices\n");
printf("\t\t2.Multiplication of two matrices.\n");
printf("\t\t3.Trace of a matrix\n");
printf("\t\t4.Transpose of matrix\n");
int a[10][10],b[10][10],c[10][10],i,j,k,sum=0,m,n,o,p,s;
printf("Select a option from the above list: \t");
scanf("%d",&s);
switch(s)
{
case 1:
printf("\n\t\t=============================>a.Addition of two matrices<==============================================\n"); printf("\n\t ***For the addition Enter the same same size of matrix*** \n"); printf("\nEnter rows and columns of the first matrix:\n"); scanf("%d %d",&m,&n); printf("\nEnter rows and columns of the second matrix:\n"); scanf("%d %d",&o,&p); printf("\nEnter the elements here for first matrix:\n"); for(i=0;ib.Multiplication of two matrices<==============================================\n"); printf("\nEnter rows and columns of the first matrix:\n"); scanf("%d %d",&m,&n); printf("\nEnter rows and columns of the second matrix:\n"); scanf("%d %d",&o,&p); if(n!=o) { printf("\nMatrix mutiplication is not possible\n"); printf("***First matrix columns are equal to second matrix rows***"); } printf("\nEnter the elements here for first matrix:\n"); for(i=0;ic.Trace of a matrix<==============================================\n"); printf("\nEnter rows and columns of the matrix:\n"); scanf("%d %d",&m,&n); printf("\nEnter the elements here for first matrix:\n"); for(i=0;id.Transpose of matrix<==============================================\n");
printf("\nEnter rows and columns of the matrix:\n");
scanf("%d %d",&m,&n);
printf("\nEnter the elements here for first matrix:\n");
for(i=0;i for(j=0;j scanf("%d",&a[i][j]);
printf("\nThe real matrix is :\n");
for(i=0;i {
printf("\n");
for(j=0;j {
printf("%d\t",a[i][j]);
}
}
printf("\n\n");
for(i=0;i for(j=0;j b[i][j]=0;
for(i=0;i {
for(j=0;j {
b[i][j]=a[j][i];
}
}
printf("\nTraspose of matrix is :\n\t");
for(i=0;i {
printf("\n");
for(j=0;j {
printf("%d\t",b[i][j]);
}
}
printf("\n\n");
break;

default :
printf("\n Choose the right option which is with in the range 1-4 only \n\n");
break;
}
}

No comments:

Post a Comment