write a program to search and display the position of an
element in a single-dimentional array using function.



write a program to search and display the position of an element in a single-dimentional array usi..

Answer / bharat varlekar

#include<iostream.h>

#include<conio.h>
#include<process.h>
#define max 10
void main()
{
clrscr();
int X[max],i,item;
for(i=0;i<max;i++)
{
cout<<”Enter “<<”X[“<< i<<”]”<<” element “;
cin>>X[i];
}
cout<<”The item to search: “;
cin>>item;
for(i=0;i<max;i++)
{
if(X[i]==item)
{
cout<<”\nItem found at “<<i+1<<” position”;
getch();
exit(1);
}
}
cout<<”\nItem not found”;
getch();
}
Output
Enter X[0] element 21
Enter X[1] element 21
Enter X[2] element 22
Enter X[3] element 35
Enter X[4] element 28
Enter X[5] element 29
Enter X[6] element 26
Enter X[7] element 23
Enter X[8] element 26
Enter X[9] element 11
The item to search: 23
Item is found at 8 position

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More STL Interview Questions

how can u do connectivity in c++ language? plz send me connectivity code in c++ ?

0 Answers   Ascent,


Is there any error below, its a code to delete all entires from a map #include <map> #include iostream.h int main() { int i =0; map <int, char> TestMap; while(i<3) { TesMap.insert(TestMap::value_type(i,Test)); i++; } typedef map<int, char> :: iterator mapIter =TestMap.begin(); if(mapIter!=TestMap.end()) { TestMap.erase(mapItrer); ++mapIter; } return 0; }

0 Answers  


What is the underlying datastructure of map?

5 Answers   BIA, Siemens,


What are the components of stl?

0 Answers  


why does the execution of a c++ program start with main()???

11 Answers  






Can we use stl in coding interviews?

0 Answers  


write a program to search and display the position of an element in a single-dimentional array using function.

1 Answers  


What do you mean by stl?

1 Answers  


What are the different types of stl containers?

0 Answers  


Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all the elements that are there in B. But B has one missing element. Write a function that takes arrays , A & B as imnput and finds the missing element in most optised manner .

4 Answers   Zycus Infotech,


How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.

0 Answers  


what is compiler?

4 Answers   NASA,


Categories