1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jok3333 [9.3K]
3 years ago
10

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 b

e 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".
Computers and Technology
1 answer:
Inessa [10]3 years ago
7 0

Answer:

The c++ program to implement search through an array is shown.

#include <iostream>

using namespace std;  

int main()  

{

   int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 };

   int input;

   int found = 0;

   cout << " This program confirms whether your element is present in the array. " << endl;

   cout << " Enter any number  " << endl;

   cin >> input;

   for( int k = 0; k < 10; k++ )

   {

       if( input == sequence[k] )

           found = found + 1;

   }

   if( found == 0 )

       cout << " Not Found " << endl;

   else

       cout << " Found " << endl;

   return 0;

}

OUTPUT

This program confirms whether your element is present in the array.  

Enter any number  

7

Found

Explanation:

The program uses the given integer array.

User is prompted to input any number. No validation is implemented for user input since it is not mentioned. The user input is taken in an integer variable, input.

int input;

cout << " Enter any number " << endl;

   cin >> input;

Another integer variable found is declared and initialized to 0.

int found = 0;

Inside for loop, each element is compared with the user input.

If the user input is present in the given array, variable found is incremented by 1.

for( int k = 0; k < 10; k++ )

   {

       if( input == sequence[k] )

           found = found + 1;

   }

If value of variable found is 0, program displays “ Not Found ”.

If the value of variable found is greater than 0, program displays “ Found ”.

if( found == 0 )

       cout << " Not Found " << endl;

   else

       cout << " Found " << endl;

This program can be tested for both positive and negative numbers.

You might be interested in
A derived class has access to __________.
Kitty [74]

Answer:

Option a is the correct answer for the above question

Explanation:

The derived class is a class that inherits the property of the base class, and he can access the public variable and function or members of the base class or ancestor class.

Option 'a' also states the same and the question asked about the assessment of the derived class. Hence option a is the correct answer while the other is not because:-

  • Option b states about the private members, but it is not accessible by the derived class.
  • Option c states about the derived class members but it can also access the base class members.
  • Option d none of the above, but option a is the correct answer.

5 0
4 years ago
The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was declared to be a l
Naily [24]

Solution :

Public Function Is a Leap_Year(Year As_Integer) As Integer

'Dim Tor_F for local variable declaring if value is t/f.

Dim TorF As For Boolean

'Pre conditions: Year > 1581 and Year < 3000

If Year > 1581 And Year <> 1700 Or 1800 Or 1900 Then

IsLeapYear = Year / 4

Else

IsLeapYear = False

TorF = False

End If

End Function

8 0
3 years ago
Write a program that displays Welcome to Java five times. INPUT and PROMPTS. None. OUTPUT. The output should be five lines of th
Leya [2.2K]

Public class WelcomeTimes5{

public static void main(String[]args){

string welcome = "Welcome to java five times" ;

system.out.println(welcome);

system.out.println(welcome);

system.out.println(welcome);

system.out.println(welcome);

system.out.println(welcome);

}

}

8 0
3 years ago
The physical address assigned each network adapter is called its ________.
zysi [14]
MAC address
....................
5 0
3 years ago
What is a credit card balance? A...The amount of interest you must pay the credit card company B...The required minimum payment
eimsori [14]
A because my sister told me and it was corecct
3 0
3 years ago
Other questions:
  • Assume you have written a method with the header num mymethod(string name, string code). the method's type is
    5·1 answer
  • What does this say:<br> √ans
    6·2 answers
  • A card ____ is a device that reads data, instructions, and information stored on flash memory cards.
    8·1 answer
  • PLEASE HELP ASAP i will mark brilliant
    12·2 answers
  • I bought an iPhone 6s Plus with 16gb three days ago and I found out that it s very little space for my liking and I want to exch
    10·1 answer
  • What provision of the Government Paperwork Elimination Act was designed to encourage a paperless society?
    6·2 answers
  • Given a string variable s that has already been declared, write some code that repeatedly reads a value from standard input into
    12·1 answer
  • A company has a website that has seen a large increase in visitors and they are concerned that if the trend continues, the web s
    13·1 answer
  • Which important aspect of the Roman Empire did the barbarians destroy?
    14·2 answers
  • What is the difference between password protection and encryption? please answer quick, i cant pass this test for the life of me
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!