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

plz tell me the solution.......... in c language program guess any one number from 1 to 50 and tell that number within 8 asking question in yes or no...............

create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }

How to reverse a String without using C functions ?

Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

Who could write how to find a prime number in dynamic array?

Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

code of a program in c language that ask a number and print its decremented and incremented number.. sample output: input number : 3 321123

main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

Categories
• C Code (421)
• C++ Code (127)
• VC++ Code (17)
• Java Code (84)
• Dot Net Code (114)
• Visual Basic Code (11)
• Programming Code AllOther (56)