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
What do you understand by friend-functions? How are they used?
Can you pass an entire structure to functions?
When should structures be passed by values or by references?
What is main () in c?
Why c is a mother language?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
What does static variable mean in c?
How can I read and write comma-delimited text?
How many levels deep can include files be nested?
What is output redirection?
What is a memory leak? How to avoid it?
What is the difference between text and binary i/o?
What is the return type of sizeof?
What is a pointer and how it is initialized?
What is atoi and atof in c?