Linear Searching in C. ( C program for Linear searching).

#include<stdio.h>
int main()
{
    int a[100],n,i,x,flag=0;
    printf("Enter size of Array:");
    scanf("%d",&n);
    printf("Enter %d elements in Array:\n",n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter element to search:");
    scanf("%d",&x);
    for(i=0; i<n; i++)
    {
        if(x==a[i])
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        printf("Element %d is found at:%d position.",x,i+1);
    }
    else
    {
        printf("Element %d is not found.",x);
    }
    return 0;
}


*** Input && Output ***




Post a Comment

0 Comments