Question

Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1,...

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".

Homework Answers

Answer #1
#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;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]...
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] W X D T P N R Q K M E If the array was being sorted using the SHELL sort and the halving method, and sorting into ASCENDING order as demonstrated in the course content, list the letters in the resulting array, in order AFTER the FIRST pass. [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Part 1: Determine what is wrong (if any) with the following statements int A[4] = {...
Part 1: Determine what is wrong (if any) with the following statements int A[4] = { 1, 2, 3, 4, 5}; int A[4] = {1,2}; int A[4] = [1,2,3,4]; Part 2: Create one dimensional array and save the following integers in it:  2, 3, 6, 7, 10, 12. Display the values on the screen. (for example, a[0] = 2, a[1] = 3, etc.) Part 3: Write a program to read 5 integers from the user. Save these integers in an array...
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a java program to display a given range of integer numbers (0 to 9) in...
Write a java program to display a given range of integer numbers (0 to 9) in the following order: Example : given (5 to 9), the program displays 56789 67895 78956 89567 95678 The first line displays the min to max range. Each line that follows should display the next higher number except when it hits the maximum number. In that situation, the line wraps back to the minimum sequence. For this problem write a static method to do the...
Pair 1 2 3 4 5 6 7 8 9 10 Medication 7 8 9 5...
Pair 1 2 3 4 5 6 7 8 9 10 Medication 7 8 9 5 6 7 7 8 8 7 Placebo 5 5 7 6 8 7 5 9 3 7 (Note: If you’re going to subtract, choose the order medication - placebo.) A sample of patients with similar weight and age characteristics were put in pairs. One patient in the pair was given medication while the other patient was given a placebo. After a month patients were...
A:  8   6   5   8   9   5   3   7   9   3   5   7   9   3   6   4  ...
A:  8   6   5   8   9   5   3   7   9   3   5   7   9   3   6   4   5   8   5   3   9 B:  3   7   9   3   5   7   9   6   8   3   5   9   6   7   8   3   7   9   5   2   8 C:  5   9   6   7   8   3   7   9   5   2   8   8   6   5   8   9   5   4   7   8   5 Using the data from the Production Run Population table what type of graph is not appropriate to...
Write a phython program to display a menu with the following options: (1) add, (2) subtract,...
Write a phython program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. If the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.