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
Digital _________ Line is a family of point-to-point technologies designed to provide high-speed data transmission over traditio
disa [49]

Answer:

D. Subscriber

Explanation:

Digital Subscriber Line is a family of point-to-point technologies designed to provide high-speed data transmission over traditional telephone lines.

The high speed data transmission property helps to transmit data in a fast and timely manner between two or more points or people during calls, texts and other activities.

6 0
3 years ago
To check for consciousness:
Lesechka [4]

The answer to your question is,

D) Check their pulse.

((Well, some people say to place your ear over the persons mouth and watch for a rise and fall of the chest-- but that's not an answer nor does that really go with any of the answers provided so..))


-Mabel <3

6 0
3 years ago
Read 2 more answers
Several of the items below indicate the steps required to move a slide to a different location in a presentation. Select those s
NikAS [45]
The answer should be
2
4
3
5
1
6
8 0
3 years ago
Read 2 more answers
Charts are inserted into an excel spreadsheet using the commands in the charts group on the ____ tab on the ribbon.
AVprozaik [17]
<span>Charts are inserted into an excel spreadsheet using the commands in the charts group on the Insert tab on the ribbon.
There, on the Insert tab, you will find many options when it comes to the things that you want to insert into your Excel spreadsheet, such as images, tables, and charts, among other things.</span>
7 0
3 years ago
Developers have proposed to build a subdivision near the shore of a lake, but this would require altering a popular wetland area
ad-work [718]
<span>They would argue that a a healthy, sustainable environment is necessary for humans. </span>Anthropocentrism is a belief that <span>interprets or regards the world in terms of human values and experiences. They see things as how they affect humans. They want to preserve the wetland so it could help humans.</span>
3 0
3 years ago
Other questions:
  • WILL GIVE BRAINLIEST! A rent payment is an example of which type of expense?
    14·2 answers
  • What class of attacks use innovative attack tools and once a system is infected it silently extracts data over an extended perio
    6·1 answer
  • Chandra, a student working on a group project, is trying to decide how to have the whole group suggest revisions for an essay. S
    10·1 answer
  • Given an list of N integers, Insertion Sort will, for each element in the list starting from the second element: Compare the ele
    8·1 answer
  • Which of the following describes the term "false information?"
    5·1 answer
  • Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a se
    12·1 answer
  • List three ways of breaking a copyright law with the illegal copy of software.​
    11·1 answer
  • What are some of the strategies that you use for confronting a complex problem and breaking it down into smaller pieces? How mig
    5·1 answer
  • You can put ______ on your phone.
    10·1 answer
  • Online platforms that allow users to represent themselves via a profile on a web site and provide and receive links to other net
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!