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;
}
}
![Test
Input Expected Got
int vet[5], n=5, b, x;
1
1
1
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);
int vet[5], n=5, b, x;
7
***Error***
vet[0]=1;
Segmentation fault
vet[1]=2;
vet[2]=3;
vet[3]=4;
vet[4]=5;
scanf("%d",&b);
x=busca_seq(vet, n, b);
printf("%d",x);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F705bcef8-c7ac-4483-b54f-9a358327c6e3%2Fc37888bb-bed7-4527-a803-ce7dd08b5954%2Ffqt6x6i_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)