write a program to search for an element in a given array.
If the array was found then display its position otherwise
display appropriate message in c language
Answer Posted / ghost
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,element,temp,pos;
clrscr();
printf("enter the array elements\n");
for (i=0; i<5; i++)
scanf("%d",&a[i]);
printf("Enter the element to be search\n");
scanf("%d",&element);
// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==element)
{
temp=1;
pos=++i;
}
}
if (temp==1)
printf("%d Element found at position==%d",element,pos);
else
printf("Element not found\n");
getch();
} // end of main()
Is This Answer Correct ? | 13 Yes | 12 No |
Post New Answer View All Answers
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
Who is the main contributor in designing the c language after dennis ritchie?
Why is sprintf unsafe?
What is a structure and why it is used?
What are all different types of pointers in c?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
What are the features of c languages?
What are local variables c?
What are enumerated types?
What do you mean by dynamic memory allocation in c? What functions are used?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
What does a function declared as pascal do differently?
What are c identifiers?
List some of the static data structures in C?
What is a floating point in c?