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
After separating from Mexico, Texas passed laws that made it harder for slave owners to _____________ slaves.
baherus [9]

Answer: b.

Explanation:

8 0
2 years ago
Read 2 more answers
Explain why much of social media marketing is trial and error.
Ivahew [28]
The first thing that entrepreneurs need to realize is that the process and framework for making social media marketing work are different from traditional marketing, and trial and error certainly doesn’t work. Ric Dragon, an expert in online marketing, in his new book “Social Marketology<span>,” outlined the best set of steps I have seen so far for the new world:</span>
7 0
3 years ago
Analyze the code and identity the value of variable a,b and c after the code execution. int a=40, b=50, c=60; if(! (a&gt;=40)) b
AlekseyPX

Answer:

a=40,b=30,c=60

The answer is B

7 0
3 years ago
3 features of digital computer​
jolli1 [7]

Answer:

A typical digital computer system has four basic functional elements: (1) input-output equipment, (2) main memory, (3) control unit, and (4) arithmetic-logic unit. Any of a number of devices is used to enter data and program instructions into a computer and to gain access to the results of the processing operation.

Explanation:

6 0
2 years ago
Which of the following technologies uses the results of a scientific discovery?
belka [17]
D. All of these
Reason being, they wouldn't have been made if something hasn't been discovered about them.

4 0
2 years ago
Read 2 more answers
Other questions:
  • Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate
    10·2 answers
  • How can you logout your account and do not want to have this anymore
    12·2 answers
  • Hello, can you help me answer these questions?
    9·2 answers
  • Which tab is used to edit objects on the slide master and layouts
    10·1 answer
  • Write a grammar for the language consisting of strings built only of the letters a and b. The strings may have any number of the
    6·1 answer
  • Define get_date() function.
    6·1 answer
  • A _____ are devices that permit a user to connect to a digital t-carrier service.
    6·1 answer
  • Which of the following is an advantage of using variables?
    9·1 answer
  • What are the peripherals of a computer ​
    12·1 answer
  • Did it surprise you to discover that the Sun is actually a star in the middle of its life cycle? Why or why not?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!