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

a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f

1577


What is static memory allocation?

597


What is #include called?

558


What is break statement?

619


What is the hardest programming language?

659






What is variables in c?

596


Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol

652


What are dangling pointers in c?

629


What is the process of writing the null pointer?

600


Explain how can I remove the trailing spaces from a string?

617


What is the method to save data in stack data structure type?

597


Explain how does free() know explain how much memory to release?

565


What are the different properties of variable number of arguments?

656


Explain the difference between the local variable and global variable in c?

587


Which is best linux os?

551