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 progarm to find the length of string using switch case?

1854


What are file streams?

781


What are identifiers c?

865


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1752


In C programming, how do you insert quote characters (‘ and “) into the output screen?

1243


Who developed c language and when?

835


How can I swap two values without using a temporary?

848


What is the use of header files?

836


List some applications of c programming language?

745


Are comments included during the compilation stage and placed in the EXE file as well?

885


What are # preprocessor operator in c?

874


Explain what is the difference between a string and an array?

905


Write a simple code fragment that will check if a number is positive or negative.

922


What is union in c?

861


What does void main () mean?

961