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 / poorni

#include<stdio.h>
#include<conio.h>

int main()
{
int a[20],i,temp=0,n,pos=0,element;
//clrscr();
printf("Search an Element in Array\n");
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value for elements: ");
scanf("%d",&a[i]);
}
printf("Enter the searching element: ");
scanf("%d",&element);
for(i=0;i<n;i++)
{
if(a[i]==element)
{
temp=1;
pos=i;
}
}
if (temp==1)
printf("Element found %d , position=%
d",element,pos);
else
printf("Element not found\n");
getch();
}

Is This Answer Correct ?    56 Yes 31 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is actual argument?

813


Explain what are compound statements?

806


What is string length in c?

817


Explain what happens if you free a pointer twice?

801


Explain how can a program be made to print the line number where an error occurs?

930


i have a written test for microland please give me test pattern

2463


in iso what are the common technological language?

1849


What is the best style for code layout in c?

827


What is variables in c?

799


What is the purpose of main( ) in c language?

865


What is difference between union and structure in c?

769


What are the differences between Structures and Arrays?

841


How to Throw some light on the splay trees?

793


What is the hardest programming language?

896


How can I make it pause before closing the program output window?

777