Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; Write a C++ program to ask the user to enter a number, if the number can be found in the array, your program should display "Found". Otherwise, your program should display "Not found". For example, if the user enters 7, your program should display "Found". If the user enters 11, your program should display "Not found".
#include <iostream> using namespace std; int main() { int sequence[10] = {3, 4, 5, 6, 7, 8, 9, 10, 1, 2}, num; bool found = false; cout << "Enter a number: "; cin >> num; for (int i = 0; i < 10; ++i) { if (sequence[i] == num) { found = true; } } if (found) { cout << "Found" << endl; } else { cout << "Not found" << endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.