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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Is stl open source?

632


totoo po ba ang manga aliens!

2334


Can we use stl in coding interviews?

1276


How do you convert stl to steps?

628


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

1971






Who created stl?

647


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

1660


please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html

1774


help me i need a c++ program which takes sequesnce of characters and outputed sequence of their token taypes, work same compiler in lexical analysis phase

1881


sir please send me bpcl previous question papers

1952


how to use C++?

2063


write a program that will accept a number and print.its equivalent in words the maximum input number is 9999

2499


How does an stl file work?

648


What is a stl vector?

625


Define stl.

773