Write a program to perform Linear search in an integer array
Answers
Answer:
Program
#include<stdio.h>
void main ()
{
int a[10] = {10, 23, 40, 1, 2, 0, 14, 13, 50, 9};
int item, i,flag;
printf("\nEnter Item which is to be searched\n");
scanf("%d",&item);
for (i = 0; i< 10; i++)
hope it's help full Army
Answer:
Linear search in C to find whether a number is present in an array. If it's present, then at what location it occurs. It is also known as a sequential search. It is straightforward and works as follows: we compare each element with the element to search until we find it or the list ends. Linear search for multiple occurrences and using a function.
Explanation:
Implementing Linear Search
Traverse the array using a for loop.
In every iteration, compare the target value with the current value of the array. If the values match, return the current index of the array. If the values do not match, move on to the next array element.
If no match is found, return -1 .