Showing posts with label Linear search in a sorted array.. Show all posts
Showing posts with label Linear search in a sorted array.. Show all posts

Sunday, June 21, 2009

Linear search in a sorted array.

Linear search in a sorted array.

#include ""
#include ""

void main( )
{
int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ;
int i, num ;

clrscr( ) ;

printf ( "Enter number to search: " ) ;
scanf ( "%d", &num ) ;

for ( i = 0 ; i <= 9 ; i++ )
{
if ( arr[9] < num || arr[i] >= num )
{
if ( arr[i] == num )
printf ( "The number is at position %d in the array.", i ) ;
else
printf ( "Number is not present in the array." ) ;
break ;
}
}

getch( ) ;
}

Featured post

Sitecore 10 Installation on Docker