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


Please Help Members By Posting Answers For Below Questions

What is bss in c?

596


What do you mean by recursion in c?

621


Is stack a keyword in c?

632


What is a pointer in c plus plus?

688


Can you explain the four storage classes in C?

639






What are the two types of functions in c?

562


What is the use of header files?

597


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

649


Explain how many levels deep can include files be nested?

622


Is there a way to jump out of a function or functions?

629


Why isnt any of this standardized in c?

629


What is meant by inheritance?

627


Differentiate between a for loop and a while loop? What are it uses?

663


What are types of preprocessor in c?

613


What is sorting in c plus plus?

561