SADDLE POINT

include

int main()
{
int i,j,r,c,small,large;

printf("Enter number of rows and coloumns\n");
scanf("%d%d", &r, &c);

int m1[r][c];

printf("Enter the elements of matrix :\n");

for(i=0; i<r; i++) {
    for(j=0; j<c; j++) {
        scanf("%d",&m1[i][j]);
    }
}


printf("Entered matrices is: \n\n");

for(i=0; i<r; i++) {
    for(j=0; j<c;j++) {
        printf("%d ",m1[i][j]);
    }
printf("\n");

}

//LOGIC PART – Small nikalne ka

small=m1[0][0];

for(i=0; i<r; i++) {

    for(j=1; j<c;j++) {

        if(m1[i][j]<small){
        small=m1[i][j];

        }

        //small kon si memory address hai pata kiya 

        for(j=0; j<c;j++) {

        if(m1[i][j]==small){
        break;

        }
       }

//LOGIC PART - jo small wala column hai kya usme wo largest hai ( in that column )

large=small;


        for(i=1; i<r; i++) {

         if(large<m1[i][j]){

        large=m1[i][j];

        }
    }

    if (large==small){
    printf("%d is the saddle point in a matrix",small);

}

    }
}






return 0;

}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *