Wednesday, 1 October 2014

WAP to compute transpose of the matrix

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],c[10][10];
int i,j,x,n;
printf("\t Enter the no. of row in Matrix ");
scanf("%d",&x);
printf("\n\t Enter the no. of column in Matrix ");
scanf("%d",&n);
printf("\n\t Enter the Matrix of A : ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\tThe Matrix is : \n");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
printf("   %d",a[i][j]);
}
printf("\n");
}
for(i=0;i<x;i++){
for(j=0;j<n;j++) {
b[i][j]= a[j][i];
}
}
printf("\n\tTranspose of Matrix is :  \n");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
printf("   %d",b[i][j]);
}
printf("\n");
}
getch();
}

WAP to perform Subtraction between two matrix.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],c[10][10];
int i,j,x,n;
printf("\t Enter the no. of row in Matrix ");
scanf("%d",&x);
printf("\n\t Enter the no. of column in Matrix ");
scanf("%d",&n);
printf("\n\t Enter the Matrix of A : ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tEnter the Matrix of B : ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<x;i++){
for(j=0;j<n;j++) {
c[i][j]= a[i][j]-b[i][j];
}
}
printf("\n\t Subtration is :  ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
printf("%d    ",c[i][j]);
}
printf("\n\t\t\t");
}
getch();
}

WAP to print the Upper triangle of the matrix

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],i,j,k;
printf("\nEnter the Matrix of 3X3 : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The Matrix is : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d",a[i][j]);
}
printf("\t\n");
}
printf("\n Upper triangular Matrix is: \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i>=j)
{
printf("\t%d",a[i][j]);
}
else
{
printf("\t0");
}
}
printf("\n");
}
getch();
}

WAP to print the Lower triangle of the matrix

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],i,j,k;
printf("\nEnter the Matrix of 3X3 : ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The Matrix is : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d",a[i][j]);
}
printf("\t\n");
}
printf("\n Lower triangular Matrix is: \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i<=j)
{
printf("\t%d",a[i][j]);
}
else
{
printf("\t0");
}
}
printf("\n");
}
getch();
}

WAP to perform Multiplication between two matrix.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],c[10][10];
int i,j,x,y,m,n,k;
printf("\t\n Enter the no. of row and column in Matrix A :");
scanf("%d%d",&x,&y);
printf("\n\t Enter the no. of row and column in Matrix B :");
scanf("%d%d",&m,&n);
printf("\n\t Enter the Matrix of A : ");
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n\tEnter the Matrix of B : ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<x;i++){
for(j=0;j<n;j++) {
for(k=0;k<y;k++){
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n\t Multiplication is :  ");
for(i=0;i<x;i++)
{
for(j=0;j<n;j++)
{
printf("%d  ",c[i][j]);
}
printf("\n\t\t\t");
}
getch();
}