Answer to Question #179401 in C for jhon

Question #179401

 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!”.


1
Expert's answer
2021-04-08T03:45:06-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS