Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

Write a program to perform linear search in 2D array.

Write a program to perform linear search in 2D array.

 #include <stdio.h>
#include<conio.h>
#define MAX 3
int create ( int [3][3] ) ;
int linearsrch ( int [3][3] ) ;
main( )
{
int mat1[3][3];
clrscr();
printf ( "\nEnter elements for first array: \n\n" ) ;
create ( mat1 ) ;
printf ( "\nFirst Array: \n" ) ;
linearsrch ( mat1 ) ;
}
create ( int mat[3][3] )
{
int i, j ;
for ( i = 0 ; i < MAX ; i++ )
{
for ( j = 0 ; j < MAX ; j++ )
{
printf ( "Enter the element: " ) ;
scanf ( "%d", &mat[i][j] ) ;
}
}
}
linearsrch ( int mat[3][3] )
{
int item,i,j;
printf("Enter the number to be searched :");
scanf("%d",&item);
for ( i = 0 ; i < MAX ; i++ )
{
for ( j = 0 ; j < MAX ; j++ )
if(item==mat[i][j])
{
printf ( "The location is :%d %d", i,j ) ;
}
}
} 

Output


Previous
Next Post »