Tuesday, May 19, 2009

Matrix Manipulations

//Title:Matrix Manipulation

#include
#include

int i, j, k;
int a[10][10], b[10][10], c[10][10];

void accept(int mat[10][10], int r, int c);
void display(int mat[10][10], int r, int c);
void addition(int mat1[10][10],int mat2[10][10],int r1,int c1,int r2,int c2);
void subtract(int mat1[10][10],int mat2[10][10],int r1,int c1,int r2,int c2);
void multiply(int mat1[10][10],int mat2[10][10],int r1,int c1,int r2,int c2);
void magic(int n);
void saddle(int a[10][10],int r,int c);

void main()
{
int res[10][10];
int ch, r1, c1, r2, c2, n;
clrscr();
do
{
printf("\n\n\nWhich operation u have to do?\n1.Add matrices");
printf("\n2.Subtract matrices\n3.Multiply\n4.Find Saddle point");
printf("\n5.Magic square\n6.Exit\nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r1,&c1);
printf("\nEnter the matrix:");
accept(a,r1,c1);
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r2,&c2);
printf("\nEnter the matrix:");
accept(b,r2,c2);
addition(a,b,r1,c1,r2,c2);
break;

case 2:
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r1,&c1);
printf("\nEnter the matrix:");
accept(a,r1,c1);
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r2,&c2);
printf("\nEnter the matrix:");
accept(b,r2,c2);
subtract(a,b,r1,c1,r2,c2);
break;

case 3:
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r1,&c1);
printf("\nEnter the matrix:");
accept(a,r1,c1);
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r2,&c2);
printf("\nEnter the matrix:");
accept(b,r2,c2);
multiply(a,b,r1,c1,r2,c2);
break;

case 4:
printf("\nEnter no. of rows and columns of matrix:");
scanf("%d %d", &r1,&c1);
printf("\nEnter the matrix:");
accept(a,r1,c1);
saddle(a,r1,c1);
break;

case 5:
printf("\nEnter order of matrix:");
scanf("%d", &n);
magic(n);
break;

case 6:
exit();
break;
}
}while(ch != 6);
getch();
}

void accept(int mat[10][10], int r, int c)
{
for(i=0;in-1)
j=0;
if(a[i][j]!=0)
{
i+=2;
j--;
}
if(i>n-1 && j<0) i="0;" i="0;" j="0;" min="p[0];">q[i])
q[i] = a[i][j];
}
}
for(k=0; kmax)
max = q[k];
}
if(min == max)
printf("\nSaddle point is present in matrix and it is %d!!!!!",min);

else
printf("\nSaddle point is not present!!!!!!");
}

No comments:

Post a Comment