Code

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Algorithm:

Since the given matrix is in ascending order, in order to search a give house nu
mber we will first
pick the first element of the first row and compare it with the given house numb
er. If the first element is
less then the house no then search further in the row. If equal then given house
is there. While
searching in the row if we does not find the house no move to the next row and r
epeat till the end. If till
end we are not able to find print that house does not exist
# include <stdio.h>
int main{
int houseno, searchno;
int n,m;
printf("enter houses no in row and coloumn in ascending order")
scanf("%d %d"&n,&m)
int array[n][m];
printf("enter the addresses");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%d",&arr[i][j]);
printf("enter the houseno to be searched ")
scanf("%d",&searchno);
int k=1;
while(flag==1)
{
for(i=0;i<m;i++)
if(arr[k][i]==searchno)
{
flag=0;
}
k++;
}
if(flag)
printf("Mr. Y does not lives in the city of Los Angeles.");
else
printf("Mr. Y lives in the city of Los Angeles. ");

You might also like