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
miss Akunina [59]
3 years ago
15

Locker doors There are n lockers in a hallway, numbered sequentially from 1 to n. Initially, all the locker doors are closed. Yo

u make n passes by the lockers, each time starting with locker #1. On the ith pass, i = 1, 2,...,n, you toggle the door of every ith locker: if the door is closed, you open it; if it is open, you close it. After the last pass, which locker doors are open and which are closed? How many of them are open?
Computers and Technology
1 answer:
kow [346]3 years ago
5 0

Answer:

// here is code in C++

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

   int n,no_open=0;

   cout<<"enter the number of lockers:";

   // read the number of lockers

   cin>>n;

   // initialize all lockers with 0, 0 for locked and 1 for open

   int lock[n]={};

   // toggle the locks

   // in each pass toggle every ith lock

   // if open close it and vice versa

   for(int i=1;i<=n;i++)

   {

       for(int a=0;a<n;a++)

       {

           if((a+1)%i==0)

           {

               if(lock[a]==0)

               lock[a]=1;

               else if(lock[a]==1)

               lock[a]=0;

           }

       }

   }

   cout<<"After last pass status of all locks:"<<endl;

   // print the status of all locks

   for(int x=0;x<n;x++)

   {

       if(lock[x]==0)

       {

           cout<<"lock "<<x+1<<" is close."<<endl;

       }

       else if(lock[x]==1)

       {

           cout<<"lock "<<x+1<<" is open."<<endl;

           // count the open locks

           no_open++;

       }

   }

   // print the open locks

   cout<<"total open locks are :"<<no_open<<endl;

return 0;

}

Explanation:

First read the number of lockers from user.Create an array of size n, and make all the locks closed.Then run a for loop to toggle locks.In pass i, toggle every ith lock.If lock is open then close it and vice versa.After the last pass print the status of each lock and print count of open locks.

Output:

enter the number of lockers:9

After last pass status of all locks:

lock 1 is open.

lock 2 is close.

lock 3 is close.

lock 4 is open.

lock 5 is close.

lock 6 is close.

lock 7 is close.

lock 8 is close.

lock 9 is open.

total open locks are :3

You might be interested in
Sound technology has been influenced the most by the ___.
GaryK [48]
I think its the phonograph i hope this helps!
5 0
3 years ago
Read 2 more answers
Type the correct answer in the box. Spell all words correctly.
Sonja [21]

An AI algorithm helps you trust the solutions that are being provided by Al systems.

<h3>What is AI?</h3>

AI is an acronym for Artificial Intelligence which is also known as Machine learning (ML) and it can be defined as a subfield in computer science that's focused on the use of advanced computer algorithms and technology to develop a smart computer-controlled robot with the abilities to proffer solutions to complex problems.

In Computer technology, an Artificial Intelligence (AI) algorithm helps you trust the solutions that are being provided by Al systems.

Read more on Artificial Intelligence here: brainly.com/question/25523571

#SPJ1

7 0
3 years ago
You can use this type of program to create a new raster image
butalik [34]

Answer:

yes

Explanation:

8 0
3 years ago
The ____ contains buttons that provide different views of the document window, and some common operations related to viewing and
alexandr402 [8]
I think it is called a document tool bar
8 0
3 years ago
A microchip company wants a computer company to produce more powerful tablets and therefore use more of its chips. That same com
Ivahew [28]

Answer:

both companies should enter into an mutual agreement.

Explanation:

Based on this information it seems that both companies should enter into an mutual agreement. By doing this they can both benefit from what the other can provide, since both provide exactly what the other needs. This will also increase profits and serve both company's stockholders well. Therefore this is the best approach that the companies can take.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
Other questions:
  • What is a relationship between a object and a class?
    6·1 answer
  • What analogy could you use to explain the hardware parts of a computer?
    11·1 answer
  • Secops focuses on integrating the need for the development team to provide iterative and rapid improvement to system functionali
    14·1 answer
  • What is obtained after processing data?​
    8·1 answer
  • Which item is most likely to be a standard part?
    14·1 answer
  • If you have created a document that contains a table that is 10 inches wide and 4 inches high, you will want to print the docume
    6·2 answers
  • You are the network adminstrator for your company your network consists of two active directory domains research.westsim.local a
    12·1 answer
  • 1. Empty tags do not have ___________.
    14·1 answer
  • How do you change your grade level
    10·1 answer
  • Full meaning of LAN and WAN
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!