Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Linear search in an unsorted array

Posted By: Tilly Hughes     Category: C Programming     Views: 4913

Linear search in an unsorted array.

Code for Linear search in an unsorted array in C Programming

#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( ) ;
}
  
Share: 


Didn't find what you were looking for? Find more on Linear search in an unsorted array Or get search suggestion and latest updates.

Tilly Hughes
Tilly Hughes author of Linear search in an unsorted array is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!