ZOHO INTERVIEW QUESTION:
Given a two dimensional array which consists of only 0’s and 1’s. Print the matrix without duplication.
Ex. INPUT :
Enter Row Size : 4
Enter column size : 3
Enter the matrix :
1 0 1
1 1 0
1 1 1
1 0 1
OUTPUT :
Unique Matrix :
1 0 1
1 1 0
1 1 1
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c[100][100],i,j,k,flag;
scanf("%d %d",&a,&b);
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
scanf("%d",&c[i][j]);
}
}
for(i=0;i<a;i++)
{
flag=0;
for(j=0;j<i;j++)
{
for(k=0;k<b;k++)
{
if(c[i][k]!=c[j][k])
break;
else if(c[i][k]==c[j][k] && k==b-1)
{
flag=1;
break;
}
}
}
if(flag==0)
{
for(j=0;j<b;j++)
printf("%d ",c[i][j]);
printf("\n");
}
}
}
Comments
Post a Comment