Sunday, February 25, 2018

C program : The smallest quadrant index


Consider a matrix M of integers. Divide M into 4 sub-matrices. These sub-matrices are called as Quadrants. Report the Quadrant number which has the smallest minimum-element. If two or more quadrants have same smallest minimum, report the smallest quadrant index. The matrix M is divided into four quadrants by halving the rows and columns. If row/column is an odd number, divide them in such a way that the first half of the row/column should be one smaller than the second half.
The four quadrants are numbered from 1 to 4 in the structure shown below: Q1 | Q2
---+---
 Q3 | Q4
INPUT FORMAT: M is a matrix of integers. You would be given two numbers m and n specifying the number of rows and columns. This would be followed by m lines of n integers each specifying the data of the m*n matrix M.
n and m will be greater than 1 and less than 12. OUTPUT FORMAT: Print in a separate line, the quadrant number with the smallest minimum-element. #include<stdio.h>
void main()
{
int a[12][12],m,n,i,j,p,q,min,row=0,col=0;
scanf("%d%d",&m,&n);

for(p=0;p<m;p++)
{

for(q=0;q<n;q++)
{
scanf("%d",&a[p][q]);

}
}
min = a[0][0];

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

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

if(min>a[i][j])
{
min=a[i][j];
row=i;
col=j;
}
}
}
if((row<m/2)&&(col<n/2))
printf("1");
else if((row<m/2)&&(col>=n/2))
printf("2");
else if((row>=m/2)&&(col<n/2))
printf("3");
else if((row>=m/2)&&(col>=n/2))
printf("4");
}
 


Thanks


Happy Computing ! 

1 comment:

Sacred Thought

26 April 2024  Dear friends, I write the explanation of two verses of Geets for all of you, I hope you all will like it and benefit from it....