Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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.

while(1)
{
// code here
if(element found)
break;
}

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..

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

More C Code Interview Questions

Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

find simple interest & compund interest

Sorting entire link list using selection sort and insertion sort and calculating their time complexity

What are the files which are automatically opened when a C file is executed?

int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }

main() { main(); }

Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.

Give a oneline C expression to test whether a number is a power of 2?

To reverse an entire text file into another text file.... get d file names in cmd line

Program to Delete an element from a doubly linked list.

What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique.

Categories