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

write a c program in such a way that if we enter the today date the output should be next day's date.

1945


What is the difference between array_name and &array_name?

1030


Explain how can I right-justify a string?

834


What are categories used for in c?

841


What are preprocessor directives in c?

878


FILE PROGRAMMING

2029


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

907


the question is that what you have been doing all these periods (one year gap)

1886


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

942


In which layer of the network datastructure format change is done

1671


Can you please explain the difference between malloc() and calloc() function?

898


What is return in c programming?

752


What are pointers in C? Give an example where to illustrate their significance.

998


Is c is a procedural language?

852


Why is main function so important?

880