Tuesday, July 10, 2018

Linear search in a unsorted array in C

Here is a simple program in C that I would like to share with you guys a linear search in a unsorted array. The code is very simple and shows how to use C language in Linear Searching.

I am currently accepting programming work, it project, school 

programming projects , thesis and capstone projects, IT consulting 

work, computer tutorials and web development work kindly contact me in the following email address for further details.  If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Program Listing

linear.c

#include <stdio.h>
#include <conio.h>

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

clrscr( ) ;

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

for ( i = 0 ; i <= 9 ; i++ )
{
if ( arr[i] == num )
break ;
}

if ( i == 10 )
printf ( "Number is not present in the array." ) ;
else
printf ( "The number is at position %d in the array.", i ) ;

getch( ) ;
}

No comments:

Post a Comment