Linear Search ( Array A, Value x)
Step 1: Set i to 1
Step 2: ifi> n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit
Write a C program for the pseudocode
Answers
Answered by
0
Answer:
#include<stdio.h>
int linearSearch(int arr[],int x,int n)
{
int i;
for(i=0;i<n;i++)
{
if(arr[i]==x)
{
printf("Element %d found at index %d",x,i+1);
break;
}
}
if(i>=n)
printf("Element not found");
}
int main()
{
int n,i;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
int x;
scanf("%d",&x);
linearSearch(arr,x,n);
}
Explanation:
Mark as brainliest : ) follow me for more answers
Similar questions