linear search using function

#include<stdio.h>

int linear_search(int n)
{
    int a[1000] , search, i , num;

    num=n;

    printf(" \n Enter the elements in the array : \t");
    for(i=0 ; i<num; i++)
    {
        scanf("%d",&a[i]);
    }

    printf("\n Enter the number to be searched :\t");
    scanf("%d",&search);

    for(i=0 ; i,num ; i++)
    {
        if(a[i]==search)
        {
            printf(" It is present at location %d",i+1);
            break;
        }
    }

    if(i ==num)
    {
        printf("The number is not present");
    }

    return 0;
}




int main()
{
    int n , x;

    printf(" Enter the number of elements : \t");
    scanf("%d",&n);

    x = linear_search(n);

    return 0;
}




OUTPUT : -

For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-


For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments