HOME

Tuesday, April 18, 2017

LINEAR SEARCH- C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,c=0, value, n, a[20];
    printf("Enter size of array\n");
    scanf("%d",&n);
    printf("Input % value\n",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter Value to Search\n");
    scanf("%d",&value);
    for(i=0;i<n;i++)
    {
        if(a[i]==value)
        {
            printf("\n%d found at position %d",a[i],i+1);
        c++;
        }
    }
    if(c==0)
    {
        printf("\nValue not found in list");
    }
getch();
}

No comments:

Post a Comment