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 / anuja kulkarni
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i;
int ele,temp=0,pos=0;
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",&ele);
// searching for the element
for (i=0; i<5; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position==%d",ele,pos);
else
printf("Element not found\n");
} // end of main()
Is This Answer Correct ? | 483 Yes | 132 No |
Post New Answer View All Answers
What is bss in c?
What do you mean by recursion in c?
Is stack a keyword in c?
What is a pointer in c plus plus?
Can you explain the four storage classes in C?
What are the two types of functions in c?
What is the use of header files?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
Explain how many levels deep can include files be nested?
Is there a way to jump out of a function or functions?
Why isnt any of this standardized in c?
What is meant by inheritance?
Differentiate between a for loop and a while loop? What are it uses?
What are types of preprocessor in c?
What is sorting in c plus plus?