how can i search an element in an array
Answers were Sorted based on User's Feedback
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 |
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 |
#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }
Write a program to receive an integer and find it's octal equivalent. How can i do with using while loop.
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
Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }
#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }
Sir... please give some important coding questions asked by product companies..
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above
4 Answers Corporate Society, HCL,
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }
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