C Program to Find out an Array Elements/Value with Linear Search

In this problem, we will see how to find an Array Elements with Linear Searching in C Program.

#include<stdio.h>
int main()
{
    int num[] = {10, 15, 25, 5, 28, 35, 60};
    int value, pos = -1, i;

    printf("Enter the value you wanna search: ");
    scanf("%d", &value);

    for(i=0; i<7; i++)
    {
        if(value == num[i])
        {
            pos = i+1;
            break;
        }
    }

    if(pos == -1)
    {
        printf("The value is not found");
    }
    else
        printf("The value %d is found at %d Possition", value, pos);

    return 0;
}

Leave a Comment