write a program to search and display the position of an
element in a single-dimentional array using function.
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 |
In what scenario does the Logical file and Physical file being used?
What are stl algorithms?
What is a standard template library (stl)? What are the various types of stl containers?
wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value
Diffrernce Between Overloading and Overriding?
How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.
if x<>=z then statement end what is the cyclomatic complexity
What is a stl vector?
If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2. please answer my question ....
What are the different types of stl containers?
How does an stl file work?
Difference between Structure and Class in C++?