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
alexgriva [62]
3 years ago
12

Write an algorithm that asks a user to enter a number between 1 and 10. (This range includes the numbers 1 and 10.) When they en

ter the number, check that it is actually between 1 and 10. If it is not, ask them to enter a number again. Continue to ask until they enter a valid number. Once their number is valid, output the number. (C++ form)
Computers and Technology
1 answer:
Nataliya [291]3 years ago
4 0

Answer:

do{

   cout<<"Introduce number \n"; //print the message

   cin>>num; //set the value of the number given

}while(num<1 || num>10); //repeat while the number is out of the range

cout<<"Number: "<<num; //print the number

Explanation:

The idea behind this code is to create a loop in which I can compare the number given  (between 1 and 10) and then print the number or get back and ask the number again.

#include <iostream>

using namespace std;

int main()

{

   int num; //create num variable

do

{

   cout<<"Introduce number \n"; //print the message

   cin>>num; //set the value of the number given

}while(num<1 || num>10); //repeat while the number is out of the range

cout<<"Number: "<<num; //print the number

}

You might be interested in
A ________________ is a special type of array that implements a last-in, first-out collection of values.
valina [46]

Answer:

A <u>stack</u> is a special type of array that implements a last-in, first-out collection of values.

6 0
2 years ago
Examples of storage device​
Mnenie [13.5K]
The answer is a usb drive
6 0
2 years ago
Write a function searchBooks which returns ALL the books written by a specific author and return the list of the book titles as
dalvyx [7]

Answer:

var library=[{author:'Bill Gates',title:'The Road Ahead',libraryID:1254},

              {author:'Abdul Kalam',title:'India 2020',libraryID:1243},

              {author:'Abdul Kalam',title:'Ignited Minds',libraryID:1200},

              {author:'Abdul Kalam',title:'Inspiring thoughts',libraryID:1200},

              {author:'Aristotle',title:'Metaphysics',libraryID:1200}

              ];

  //author of the book to be searched

  var authorName='Abdul Kalam';

  //document.write() will write in the html page

  a=searchBooks(library,authorName);

  books=a[0];

  authorNames=a[1];

  //<h1></h1> is used to make heading Books

  document.write("Books:\n");

  for(i=0;i<books.length;i++)

      document.write(books[i]['author']+" --> "+books[i]['title']+" --> "+books[i]['libraryID']+"<br>");

  document.write("Titles:\n"+a[1]);

  function searchBooks(library,authorName){

      //empty string to assign book names

      list_of_titles='';

      books=[];

      //reading each book from 0th position to last

      for(i=0;i<library.length;i++){

          //if author is authorName then add it to list_of_titles

          if(library[i]['author']==authorName){

              books.push(library[i]);

              list_of_titles+=library[i]['title']+",";

          }

      }

      //removing the last comma

      list_of_titles=list_of_titles.slice(0,-1);

      //if list_of_titles is empty return NOTFOUND

      if(list_of_titles=='')

          return 'NOT FOUND';

      //if books are found return list_of_titles

      else

          return [books,list_of_titles];

      //returning the list of books and titles

  }

4 0
2 years ago
Consider the following algorithm: ```c++ Algorithm Mystery(n) { // Input:A nonnegative integer n S = 0; for i = 1 to n do { S =
jasenka [17]

Answer:

See explanation

Explanation:

First let us find what this algorithm compute:

Algorithm Mystery(n) {

        S = 0;

        for i = 1 to n do

             { S = S + i * i; }

         return S }

1)

Let suppose n = 3

S = 0

The algorithm has a for loop that has a loop variable i initialized to 1

At first iteration:

i = 1

S = S + i * i;

   = 0 + 1 * 1

S = 1

At second iteration:

i = 2

S = 1

S = S + 2 * 2;

   = 1 + 2 * 2

   = 1 + 4

S = 5

At third iteration:

i = 3

S = 5

S = S + 3 * 3;

   = 5 + 3 * 3

   = 5 + 9

S = 14

Now the loop breaks at i=4 because loop iterates up to n and n =3

So from above example it is clear that the algorithm computes the sum of squares of numbers from 1 to n. Or you can say it compute the sum of first n squares.  Let us represent this statement in mathematical form:

∑\left \ {{n} \atop {i=1}} \right. i²

2)

From above example we can see that the basic operation is multiplication. At every iteration loop variable i is multiplied by itself from 1 to n or till n times. However we can also say that addition is the basic operation because at each iteration the value of S is added to the square of i. So it takes the same amount of time.

3)

In the for loop, the basic operation executes once. We can say that at each iteration of the loop, multiplication is performed once. Suppose A(n) represents the number of times basic operation executes then,

A(n) = ∑\left \ {{n} \atop {i=1}} \right. 1 = n

4)

Since for loop executes once for each of the numbers from 1 to n, so this shows that for loop executes for n times. The basic operation in best, worst or average case runs n times. Hence the running time of Θ(n) . We can say that A(n) = n ∈ Θ(n)  

If b is the number of bits needed to  represent n then

b = log₂n + 1

b = log₂n

So

n ≈ 2^{b}

A(n) ≈ 2^{b} ≈ Θ( 2^{b} )  

5)

One solution is to calculate sum of squares without using Θ(n) algorithm.  So the efficient algorithm that takes less time than the previous algorithm is:

Algorithm Mystery(n) {

        S = 0;

        S = (n * ( n + 1 ) (2n + 1) ) / 6 ;

        return S}

Now the sum can be calculated in Θ(1)  times. This is because regardless of the size and number of operands/operations, the time of arithmetic operation stays the same. Now lets find out how this algorithm works for

n = 3

S = (n * ( n + 1 ) (2n + 1) ) / 6 ;

 = (3 * ( 3 + 1 ) * (2(3) + 1) ) / 6

 = (3 * (4) * (6+1)) / 6

= (3 * (4) * (7)) / 6

= (3 * 4 * 7) / 6

= 84 / 6

S = 14

3 0
3 years ago
________ are chunks of software - installed on one's computer, tablet, or smartphone - that are gateways to games, online resour
Stella [2.4K]

Answer:

Apps

Explanation:

Mobile applications or apps refer to software applications designed specifically for small computing devices especially tablets and smart phones and not the regular desktop and laptop computers.

The design of mobile apps puts into consideration the specifics of these smaller computing devices such screen constraints and their special capabilities as well (e.g iPhone's accelerometer).

They are categorized into native (specific platform e.g android) or web-based apps.

5 0
3 years ago
Other questions:
  • What does confidentiality of data refer to?
    6·2 answers
  • Some cases have ____, also called spacers, which are round plastic or metal pegs that separate the motherboard from the case, so
    9·1 answer
  • What makes us see continuously moving images when still images appear in rapid succession
    11·1 answer
  • 1.Electromagnetic waves can carry more data at higher frequencies. Why would a scientist opt to transmit data at a lower frequen
    12·1 answer
  • Which of the following would be a show stopper for the development of an enterprise mobile app? The app demands data throughput
    11·1 answer
  • Do you agree with the EU's decision that people should be able to ask Google to remove search results that contain incorrect, un
    11·2 answers
  • In c#, how are parameters passed on?
    15·2 answers
  • In order to enhance the training experience and emphasize the core security goals and mission, it is recommended that the execut
    5·1 answer
  • How to write the algorithm to calculate the square of five numbers
    14·2 answers
  • a ____ is a window inside the word window that can remain open and visible while you work in a document.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!