☞ Given an n-by-n matrix of 0's and 1's where all 1's in each row come before all 0's, find the most efficient way to return the row with the maximum number of 0's.
#include<stdio.h>
int main(){
int mtrx[10][10],n,i,j,r,mz,zc=0;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mtrx[i][j]);
r=0;
mz=0;
for(i=0;i<n;i++){
zc=0;
for(j=0;j<n;j++){
if(mtrx[i][j]==0)
zc++;
}
if(mz<zc){
mz=zc;
r=i;
}
}
printf("%d",r);
return 0;
}
Sample Input::
4
1 1 1 0
1 1 0 0
1 0 0 0
1 1 0 0
Sample Output::
2
For mini projects click here
CSE Materials click here
#include<stdio.h>
int main(){
int mtrx[10][10],n,i,j,r,mz,zc=0;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mtrx[i][j]);
r=0;
mz=0;
for(i=0;i<n;i++){
zc=0;
for(j=0;j<n;j++){
if(mtrx[i][j]==0)
zc++;
}
if(mz<zc){
mz=zc;
r=i;
}
}
printf("%d",r);
return 0;
}
Sample Input::
4
1 1 1 0
1 1 0 0
1 0 0 0
1 1 0 0
Sample Output::
2
For mini projects click here
CSE Materials click here