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...
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...
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...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8;...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8; int x[8] = {2, 3, 5, 7, 11, 13, 17, 19}; scanf("%d",&k); aux = x[k]; for (int i = k; i < size - 1; i++) x[i] = x[ i + 1]; x[ size - 1] = aux;   for (int i = 0; i < size; i++) printf("%d ", x[i]); } change this program to Write a program to remove an element from an...
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...
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and let the...
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and let the digits of your ID to be the elements of set A. For example if my ID is 21743911, then set A would be {2,1,7,4,3,9}. Write the bit string that represents set A above. Let set B = {2, 3, 5, 6, 7, 10}. Write the bit string that represents this set B. What is the bit string for the difference of A and B?...
Let U = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, A = {5,...
Let U = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, A = {5, 7, 9, 11, 13}, B = {6, 8, 10, 12, 14}, and C = {5, 6, 8, 9, 12, 13}. List the elements of each set. (Enter your answers using roster notation. Enter EMPTY or ∅ for the empty set.) (a)    Ac ∩ (B ∩ C c) (b)    (A ∪ Bc) ∪ (B ∩ C c) (c)    (A ∪ B)c ∩ C c
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
Let p = (8, 10, 3, 11, 4, 0, 5, 1, 6, 2, 7, 9) and...
Let p = (8, 10, 3, 11, 4, 0, 5, 1, 6, 2, 7, 9) and let q = (2, 4, 9, 5, 10, 6, 11, 7, 0, 8, 1, 3) be tone rows. Verify that p = Tk(R(I(q))) for some k, and find this value of k.