how can i search an element in an array

Answers were Sorted based on User's Feedback

how can i search an element in an array..

Answer / pavan_mustyala

In C-Language, In general, we compare each element of the
array in a loop that iterates till the element is found.
This is called Linear search.

// code here
if(element found)

Here, execution time depends on the array size and position
of the element in the array.
For sorted arrays, we can use techniques such as binary
search using which execution is faster.

Is This Answer Correct ?    2 Yes 0 No

how can i search an element in an array..

Answer / palanisaran

my $element = 'Whatever you are searching for' ;
if (grep {$_ eq $element} @TheArray) {
print "Element '$element' found!\n" ;

Is This Answer Correct ?    4 Yes 9 No

Post New Answer

More C Code Interview Questions

What is "far" and "near" pointers in "c"...?

3 Answers  

write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

0 Answers  

How do you write a program which produces its own source code as its output?

7 Answers  

main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }

1 Answers  

main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

1 Answers  

main() { char *p; p="Hello"; printf("%c\n",*&*p); }

1 Answers  

main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above

2 Answers   HCL, LG,

write a program for area of circumference of shapes

0 Answers  

main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }

2 Answers  

How to access command-line arguments?

4 Answers  

main() { int i=5; printf(ā€œ%dā€,i=++i ==6); }

1 Answers  

main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }

1 Answers