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

What is stl in oop?

0 Answers  


Find the error in the following program struct point {struct point *next; int data; } x; main() {int...data; } x; main() {int i; for(x=p;x!=0;) x=x->next,x++; freelist(x); } freelist(x) {free(x); return }

1 Answers   Sun Microsystems,


what's the difference between abstract class and concreate class? what's the meaning of standard template library(STL)?

2 Answers  


What are stl algorithms?

0 Answers  


Write a program in C++ to concatenate two strings into third string using pointers

5 Answers  


What is C++ could you enplane me please?

1 Answers  


What is Constructor

14 Answers   Angel Broking,


draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

0 Answers   Appin, NIIT,


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

1 Answers  


What do stl stand for?

0 Answers  


tell about sorted linked list

1 Answers  


What do you mean by stl?

1 Answers  


Categories