Skip to content

Instantly share code, notes, and snippets.

@Praful932
Created July 18, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Praful932/8441c2b77b585d7589262279032c51d8 to your computer and use it in GitHub Desktop.
Save Praful932/8441c2b77b585d7589262279032c51d8 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void accept(int [][10],int ,int);
void acceptp(int )
void display(int [][10],int,int);
void add(int [][10],int [][10],int,int,int,int);
void transpose(int[][10],int,int);
void multi(int [][10],int [][10],int m,int n,int x,int y);
void saddle(int [][10],int m,int n);
int minrow(int a[][10],int ccol,int n,int crow);
int maxcol(int a[][10],int crow,int m,int ccol);
int main()
{
int m1[10][10],m2[10][10],m,n,x,y,s,c;
printf("Enter rows and columns resp. for Matrix 1\n");
scanf("%d %d",&m,&n);
printf("Enter rows and columns resp. for Matrix 2\n");
scanf("%d %d",&x,&y);
printf("Enter elements for Matrix1\n");
accept(m1,m,n);
printf("Enter elements for Matrix2\n");
accept(m2,x,y);
printf("1.Addition\n2.Transpose\n3.Multiplication\n4.Saddle Point \n 0.Exit");
printf("Enter choice:\n");
scanf("%d",&s);
//if(s==0)
//break;
switch(s)
{
case 1:
if(m==x && n==y)
add(m1,m2,m,n,x,y);
else
printf("Both matrix should have equal rows and columns");
break;
case 2:
printf("Transpose of:\n 1.Matrix 1 \n2.Matrix2");
scanf("%d",&c);
if (c==1)
transpose(m1,m,n);
else
transpose(m2,x,y);
break;
case 3:
if(n==x)
multi(m1,m2,m,n,x,y);
else
printf("Column of 1st matrix should be equal to row of2nd matrix");
break;
case 4:
printf("\nSaddle point of:\n 1.Matrix 1 \n2.Matrix2");
scanf("%d",&c);
if (c==1)
saddle(m1,m,n);
else
saddle(m2,x,y);
break;
default:
printf("Wrong Choice");
}
return 0;
}
void accept(int m[][10],int x,int y)
{
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
scanf("%d",&m[i][j]);
}
}
void display(int m[][10],int x,int y)
{
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
printf("%d\t",m[i][j]);
printf("\n");
}
printf("\n");
}
void add(int m1[][10],int m2[][10],int m,int n,int x,int y)
{
int add[10][10];
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
add[i][j]=m1[i][j] + m2[i][j];
}
printf("\n");
display(add,m,n);
}
void transpose(int m[][10],int x,int y)
{
int trans[10][10];
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
trans[j][i]=m[i][j];
}
printf("\n");
display(trans,x,y);
}
void multi(int m1[][10],int m2[][10],int m,int n,int x,int y)
{
int mul[10][10],sum=0,j;
for(int i=0;i<m;i++)
{
for(int j=0;j<y;j++)
{
mul[i][j]=0;
for(int k=0;k<n;k++)
{
mul[i][j]=mul[i][j]+(m1[i][k]* m2[k][j]);
}
printf("%d\t",mul[i][j]);
}
printf("\n");
}
printf("\n");
}
void saddle(int a[][10],int m,int n)
{
int min,max;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
maxc=maxcol(a,i,m,j);
minr=minrow(a,j,n,i);
if(maxc==minr)
printf("Saddle Point : %d\n",a[i][j]);
}
}
}
int maxcol(int a[][10],int crow,int m,int ccol)
{
int max=a[ccol][crow];
for(int i=0;i<m;i++)
{
currentelement=a[i][crow];
if(currentelement>max)
max=currentelement;
}
return max;
}
int minrow(int a[][10],int ccol,int n,int crow)
{
int currentelement;
int min=a[crow][ccol];
for(int j=0;j<n;j++)
{
currentelement=a[j][ccol];
if(currentelement<min)
min=currentelement;
}
return min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment