create a program using one dimensional array that accept five inputted numbers. Then it should accept for a number to be search among the five inputter numbers. If it is found, display the message “searched number is found!”, otherwise “search number is lost!”.
#include <iostream>
using namespace std;
int main()
{
// we declare an one-dimensional array that accepts five element
int arr[5];
// we should enter the elements of array from keyboard
cout << "Enter 5 numbers: " << endl;
for (int i = 0; i < 5; i++) {
cin >> arr[i];
}
cout << "The entered array is : " << endl;
for (int i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
// we declare a variable for search the element in array
int number_searched;
cout << "\nEnter a number to search: " << endl;
cin >> number_searched;
int t = 0;
for (int i = 0; i < 5; i++) {
if (number_searched == arr[i]) {
cout << "Searched number is found!";
break;
}
t++;
}
if (t == 5) {
cout << "Search number is lost!";
}
return 0;
}
Comments
Leave a comment