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
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
What is static memory allocation?
What is #include called?
What is break statement?
What is the hardest programming language?
What is variables in c?
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
What are dangling pointers in c?
What is the process of writing the null pointer?
Explain how can I remove the trailing spaces from a string?
What is the method to save data in stack data structure type?
Explain how does free() know explain how much memory to release?
What are the different properties of variable number of arguments?
Explain the difference between the local variable and global variable in c?
Which is best linux os?