You are on page 1of 3

#include<stdio.

h>
#include<conio.h>
void add(int *,int *,int,int);
void multiply(int *,int,int,int *,int,int);
void transpose(int *,int,int);
void saddle(int *,int,int);
void main()
{
int i,j,m,n,m1,n1,ch,a[5][5],b[5][5];
char ans;
clrscr();
printf("\nEnter the no of rows and columns of first matrix:");
scanf("%d%d",&m,&n);
printf("\nEnter the no of rows and columns of second matrix:");
scanf("%d%d",&m1,&n1);
printf("\nenter the first matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nenter the second matrix"):
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
scanf("%d",&b[i][j]);
}
}
do
{
clrscr();
printf("\nChoose the operation you want to perform\n1)Addition\n
2)Multiplication\n3)Transpose\n4)Saddle");
scanf("%d",&ch);
switch(ch)
{
case1:
if(m==m1 && n==n1)
add(&a[0][0],&b[0][0],m,n);
else
main();
break;
case2:
if(n==m1)
multiply(&a[0][0],m,n,&b[0][0],m1,n1);
else
main();
break;
case3:
transpose(&a[0][0],m,n);
break;
case4:
saddle(&a[0][0],m,n);
break;
default:
printf("\nwrong choice");
break;

}
printf("\nDo you want to continue\n");
scanf("\n%c",&ans);
}
while(ans=='y'|| ans=='Y');
getch();
}
void add(int *p,int *q,int m,int n)
{
int i,j;
printf("\nThe addition of matrices is:\n);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d",*(p+i*n+j) + *(q+i*n+j);
}
printf("\n");
p=p+(5-n);
q=q+(5-n);
}
}
void multiply(int *p,int m,int n,int *q,int m1,int n1)
{
int i,j,k,sum=0;
printf("\nThe multiplication of matrices is:\n");
for9i=0;i<m;i++);
{
for(j=0;j<n1;j++)
{
sum=0;
for(k=0;k<n;k++)
{
sum=sum + *(p+i*n+k) * *(q+5*k);
}
printf("%d",sum);
q=q+1;
}
printf("\n");
p=p+(5-n);
q=q-n1;
}
}
void transpose(int *p,int m,int n)
{
int i,j;
printf("\nThe transpose of the matrix is :\n");
for(i=0;i<m;i++);
{
for(j=0;j<n;j++)
{
printf("%d",*(p+5*j+i);
}
printf("\n");
}
}
void saddle(int *p,int m,int n)
{
int i,k,flg,x,cnt=0,j;
for(i=0;i<m;i++)

{
flg=*(p+5*i);
for(j=0;j<n;j++)
{
if(*(p+5*i+j)>flg)
{
flg=*(p+5*i+j);
x=j;
}
}
cnt=0;
for(k=0;k<m;k++)
{
if(flg<=*(p+x+5*k))
cnt=cnt++;
else
break;
}
if(cnt==m)
printf("\n the saddle pnt is %d",flg);
else
printf("no saddle point");
}
}

You might also like