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
What is variable initialization and why is it important?
How can I call fortran?
How is a structure member accessed?
Explain how can I pad a string to a known length?
Explain what is wrong with this statement? Myname = ?robin?;
What are identifiers and keywords in c?
What are the properties of union in c?
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.
How can I read data from data files with particular formats?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
How do you list a file’s date and time?
Does sprintf put null character?
Why is c not oop?
Explain the advantages of using macro in c language?
What are the types of variables in c?