wite a programme in c to linear search a data using flag and
without using flags?

Answer Posted / st0le

int linearSearch(int a[],int ub,int key)
{
for(int i=0;i<n;i++)
if(a[i] == key) return i;
return -1; //not found!
}

int linearSearch(int a[],int ub,int key)
{
int flag = 0;
for(int i=0;i<n;i++)
if(a[i] == key)
{ flag = 1; break; }

return (flag)? i:-1; //not found!
}

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between test design and test case design?

1578


write a proram to reverse the string using switch case?

2474


What is property type c?

609


Explain how can you avoid including a header more than once?

607


What are qualifiers and modifiers c?

553






What are file streams?

574


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

1869


write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.

1989


Define VARIABLE?

692


Write a program to check prime number in c programming?

604


What does c mean?

594


Is flag a keyword in c?

683


Explain can you assign a different address to an array tag?

649


What is a buffer in c?

579


write a program to print largest number of each row of a 2D array

1876