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
A Windows user contacted the help desk with a problem that requires the technician to connect to the remote computer using Remot
djverab [1.8K]

Answer:

RDP port 3389 .

Explanation:

A Windows user has informed the helpdesk with such an issue that requires the operator to link to the remote server through Remote Assistance to access the user's screen with a very comprehensive and ambiguous error message. Almost any attempt made by the operator to link to the remote access concludes in a message that says that the connection has been denied. To make this link, the following protocol and the port number combinations must be enabled on the firewall of the remote connection.

6 0
3 years ago
​Lisa mentions that a program is developed to interact with other programs, and she wants to begin by testing the programs indiv
Ronch [10]

QC TESTER(quality testing process) is the name of this process.

To name this process call QC TESTER

<u>Explanation:</u>

Any software development environment their will QC testing (quality testing process) where end user will do or simulate complete testing of software make the software bug free.

After QC tester confirm the program as bug free then only software implementation team ready for implementation process. QC tester is important role in software development environment to find a bug on function, data input entry and monitor result from software and inform to software team with list of bug results.

This process will take place to and from between QC tester and software developer team till software become bug free.  

6 0
3 years ago
Write down eight points on how modern technology have effected our life ?
luda_lava [24]

Answer:

  1. Made everyday activities easy to do
  2. We have become dependant on mordern technology
  3. We use the internet for everything
  4. Meetings can be done online
  5. food can be ordered and delivered online
  6. Payments can be done using technology
  7. We pay more attention to social media
  8. Meet new people online
3 0
3 years ago
Assume that to_the_power_of is a function that expects two integer parameters and returns the value of the first parameter raise
Bezzdna [24]

Answer:

The statement in python is as follows:

to_the_power_of(cube_side,3)

Explanation:

As stated as the requirement of the code segment, the statement takes as parameters a variable cube_side and a constant 3.

It then returns the volume of the cube; i.e. cube raise to power 3

<em></em>

<em>See full program below</em>

<em>def to_the_power_of(val,powe):</em>

<em>     result = val**powe</em>

<em>     print(result)</em>

<em>cube_side = float(input("Cube side: "))</em>

<em>to_the_power_of(cube_side,3)</em>

4 0
3 years ago
The __________ endian storage format places the __________ byte of a word in the lowest memory address. The __________ endian st
mr Goodwill [35]

Answer:

i. Big

ii. most significant

iii. little

iv. most significant

Explanation:

8 0
3 years ago
Other questions:
  • What is a way to Procter your social security number and other sensitive information from identity theft
    9·1 answer
  • The set of rules for how computers talk to one another
    6·1 answer
  • (1 consider the following function definition: int func(int x, double y, char u, string name { //function body } which of the fo
    7·1 answer
  • Some data files should be totally hidden from view, while others should have ____ so users can view, but not change, the data.
    11·1 answer
  • A computer has the following parameters Operation Frequency Cycles Arithmetic/Logical instructions 65% 1 Register load operation
    11·1 answer
  • What are some (free) good animation websites (for PC/Microsoft) for a short informational video about homelessness?
    15·1 answer
  • Heidi uses her computer to write articles for a newspaper. She uses a program to listen to the articles before she submits them
    5·1 answer
  • Here is a list of storage devices:
    5·1 answer
  • Write a recursive function num_eights that takes a positive integer pos and returns the number of times the digit 8 appears in p
    8·1 answer
  • Windows hard disks can now use a variety of file systems, including FAT16, FAT32, ____, and Resilient File System.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!