Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Program for Linear Search.

Program: Linear Search

/*Program for Linear Search*/

/*Header Files*/

#include

#include

/*Global Variables*/

int search;

int flag;

/*Function Declarations*/

int input (int *, int, int);

void linear_search (int *, int, int);

void display (int *, int);

/*Functions */

void linear_search(int m[ ], int n, int el)

{

int k;

flag = 1;

for(k=0; k

{

if(m[k]==el

{

printf("\n Searching is Success\n");

printf("\n Element : %i Found at location : %i", element, k+1);

flag = 0;

}

}

if(flag==1)

printf("\n Searching is unsuccessful");

}

void display(int m[ ], int n)

{

int i;

for(i=0; i< 20; i++)

{

printf("%d", m[i];

}

}

int input(int m[ ], int n, int el)

{

int i;

n = 20;

el = 30;

printf("Number of elements in the list : %d", n);

for(i=0;i<20;i++)

{

m[i]=rand( )%100;

}

printf("\n Element to be searched :%d", el);

search = el;

return n;

}

/* Main Function*/

void main( )

{

int n, el, m[200];

number = input(m, n,el);

el = search;

printf("\n Entered list: \n");

display(m, n);

linear_search(m, n, el);

printf("\n In the following list\n");

display(m, n);

}

Program 1 examines each key value in the array 'm', one by one and stops while a match occurs or the entire array is searched.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9536936

Have any Question?


Related Questions in Computer Engineering

A financial analyst examined the possible returns from

A financial analyst examined the possible returns from several financial investments. When the performance of these investments was later examined, it turned out that 25% performed much better than the market average, 25 ...

Calculate the energy of one photon of blue light that has a

Calculate the energy of one photon of blue light that has a wavelenght of 425 nm and red light that has a wavelenght of 740 nm. Use E = hv and C = frequency x wavelenght(v). And determine which photon has highest energy.

Naomi always eats bagels with 1 ounce of cream cheese each

Naomi always eats bagels with 1 ounce of cream cheese. Each bagel eaten in this way provide 15 units of utility. Excess cream cheese or excess bagels do not add to Naomi's utility. Explain the nature of Naomi's utility f ...

What is the difference between accounting costs and

What is the difference between accounting costs and economic costs? Why do economic costs include both explicit (revealed and expressed) costs and implicit (present but not obvious) costs? What are the differences betwee ...

A salesforce from an ecommerce global organization has

A salesforce from an ecommerce global organization has begun to raise some concerns about the orders they are transmitting over the Internet from their customers' site to the organization's global headquarters. It seems ...

Question suppose an instruction can be carried out in 3

Question : Suppose an instruction can be carried out in 3 stages, the stages taking 3 ns, 7 ns, and 10 ns, respectively. (a) What is the maximum execution rate without pipelining? (b) What speedup is possible with pipeli ...

Question suppose you want to implement a sudoku game that

Question : Suppose you want to implement a Sudoku game that includes nine rows and nine columns of squares. Which layout would be the best one to use and why? The response must be typed, single spaced, must be in times n ...

Question you are responsible for managing multiple exchange

Question : You are responsible for managing multiple Exchange organizations, and you need to apply identical configurations to servers in all organizations. Since you are just starting out with Exchange Server 2013, and ...

Solve the following problem from fibonaccis liber abacia

Solve the following problem from Fibonacci's Liber abaci: A man left to his eldest son one bezant and a seventh of what was left; then from the remainder, to his next son he left two bezants and a seventh of what was lef ...

Strong passwords are at least 8 characters in length

Strong passwords are at least 8 characters in length, contain both upper- and lower-case letters, as well as some digits and special characters. Use the requirements (specified below) for a password to define in BNF a gr ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As