Write a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq".
Code in C. Solve the code below.
Write a function that takes a
int busca_seq(int vetor[], int n, int b)
{
//your code
}
My Code
#include<stdio.h>
int busca_seq(int vetor[], int n, int b)
{
int i;
for(i = 0; i < n; i++){
if(vetor[i] == b)
return (i+1);
}
{
int vet[5],n = 5,b,x;
vet[0] = 1;
vet[1] = 2;
vet[2] = 3;
vet[3] = 4;
vet[4] = 5;
scanf("%d",&b);
x = busca_seq(vet,n,b);
printf("%d",x);
return 0;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images