Write a c Program to perform Linear Search. - Data Structure using C

Translate

Sunday, December 6, 2020

Write a c Program to perform Linear Search.

 Write a c Program to perform Linear Search.

#include<stdio.h>

int main()

{

    int array[100],a,c,n;

    

    scanf("%d",&n);

    scanf("%d",&a);

    

    for (c=0; c<n; c++)

    scanf("%d",&array[c]);

    

    for(c=0; c<n; c++)

    {

    if (array[c] == a)

        {

            printf("%d",c);

            break;     

       }

    }

    if (c == n)

    printf("-1");

    return 0;

}

No comments:

Post a Comment

Introduction to Arrays

  Introduction to Arrays An array is a data structure that allows you to store a collection of elements of the same type. Each element in th...