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
Explain what is wrong with this statement? Myname = ?robin?;
How are pointers declared in c?
write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list
What are loops in c?
What is the difference between the expression “++a” and “a++”?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
How can I avoid the abort, retry, fail messages?
What is structure in c explain with example?
All technical questions
How do you redirect a standard stream?
What is hungarian notation? Is it worthwhile?
Describe explain how arrays can be passed to a user defined function
What is dangling pointer in c?
What are header files in c?
What is a pointer on a pointer in c programming language?