Skip to main content

Linear Search

 



#include <stdio.h>
int main()
{
    int a[10], n, item;
    printf("Enter the length of the array: ");
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    printf("Element item you wanna find: ");
    scanf("%d", &item);
    for (int i = 0; i < n; i++)
    {
        if (a[i] == item)
        {
            printf("Element Found at %d position", i);
            return 0;
        }
    }
    printf("Opps! Element not found");

    return 0;
}

Comments