Question #167896

1.Write a program using one-dimensional array that accept 5 input values from the keyboard. Then it 

should also accept a number to search. This number is to be searched if it is among the five inputs. If 

it is found, display the message “Searched number is found!”, otherwise display “Search number is not 

included in the list”.


Sample Output:

Enter five values:

5 10 15 20 25

Enter a number to search: 15

Search number is found!


Expert's answer

#include <iostream>  
  
using namespace std; 
  
//The start point of the program
int main() 
{   
	//one-dimensional array that accept 5 input values from the keyboard. 
	float values[5];
	float searchNumber;
	bool isFound=false;
	cout<<"Enter five values\n"; 
	for(int i=0;i<5;i++){
		cin>>values[i];
	}
    //accept a number to search.
	cout<<"Enter a number to search: ";
	cin>>searchNumber;
	//This number is to be searched if it is among the five inputs
	for(int i=0;i<5;i++){
		if(values[i]==searchNumber){
			isFound=true;
		}
	}
	//If it is found, display the message "Searched number is found!"
	if(isFound){
		cout<<"Searched number is found!\n\n";
	}else{
		//otherwise display "Search number is not  included in the list".
		cout<<"Search number is not  included in the list\n\n";
	}
    return 0; 
} 
LATEST TUTORIALS
APPROVED BY CLIENTS