answer.
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]
2 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]2 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
Poor quality lateral communication will result in which ofthe
zhuklara [117]

Answer:

b

Explanation:

b, lack of coordination

3 0
2 years ago
Read 2 more answers
Choose the correct function to convert the user’s response to the number 3.5. &gt;&gt;&gt; answer = input("How much does the sam
FromTheMoon [43]

Answer:

The answer to the given question is given bellow in the explanation section:

Explanation:

<p>This is python code</p>

<p>In python when you enter input into the input function as given:</p>

<code> answer = input("How much does the sample weigh in grams? ") </code>

I will be taken as string.

So I have to convert this string to number format here the given data is float value i-e 3.5

so let convert it. using float function.

<code> answer = float (input("How much does the sample weigh in grams? ") )  </code>

6 0
1 year ago
Read 2 more answers
A painting company has determined that for every 115 square feet or wall space, one gallon of paint and eight hours of labor wil
Kay [80]

The program to calculate the total paint cost and other values is given below.

#include <iostream>

using namespace std;

int main() {  

 int rooms, laborChrg = 18;

 float paintChrg;

 float feetPerRoom[rooms];  

 float paintReq, laborHrs, paintCost, laborCost, totalCost, totalsqft=0;  

 cout<<"Enter the number of rooms to be painted "<<endl;

 cin>>rooms;  

 for(int i=0; i <= rooms; i++)

 {

 cout<<"Enter the square feet in room "<<endl;

 cin>>feetPerRoom[i];  

 // shortcut operator which is equivalent to totalsqft = totalsqft +     feetPerRoom[i];

 totalsqft += feetPerRoom[i];

 }  

 cout<<"Enter the cost of the paint per gallon "<<endl;

 cin>>paintChrg;  

 laborHrs = (totalsqft/115)*8;

 laborCost = laborHrs * laborChrg;  

 paintReq = totalsqft/115;

 paintCost = paintReq * paintChrg;  

 totalCost = laborCost + paintCost;  

 cout<<"The number of gallons of paint required "<<paintReq<<endl;

 cout<<"The hours of labor required "<<laborHrs<<endl;

 cout<<"The cost of the paint is "<<paintCost<<endl;

 cout<<"The labor charges are "<<laborHrs<<endl;

 cout<<"The Total cost of the paint job is "<<totalCost<<endl;  

 return 0;

}

Explanation:

The header files for input and output are imported.

#include <iostream>

using namespace std;

All the variables are taken as float except labour charge per hour and number of rooms.

The user is asked to input the number of rooms to be painted. An array holds the square feet in each room to be painted.

cout<<"Enter the number of rooms to be painted "<<endl;

cin>>rooms;  

for(int i=0; i <= rooms; i++)

{

cout<<"Enter the square feet in room "<<endl;

cin>>feetPerRoom[i];  

totalsqft += feetPerRoom[i];

}  

The above code asks for square feet in each room and calculates the total square feet to be painted simultaneously.

All the data to be displayed is calculated based on the values of labor charge per hour and gallons of paint needed, given in the question.

laborHrs = (totalsqft/115)*8;

laborCost = laborHrs * laborChrg;

paintReq = totalsqft/115;

paintCost = paintReq * paintChrg;

totalCost = laborCost + paintCost;

All the calculated values are displayed in the mentioned order.

7 0
2 years ago
_____________ helps to control and limit the number of consecutive request failures that cross a threshold. Review breaker Micro
True [87]

Answer:

Circuit breaker

Explanation:

Circuit breaker -

It is a type of electrical switch , whose main function is to protect the electrical circuit by the process of short circuit or overloading , is referred to as a circuit breaker .

The circuit breaker , as the name suggests , disrupts the circuit as soon as there is the condition of overloading or short circuit , and thereby saves the appliances .

Hence , from the given information of the question,

The correct term is circuit breaker  .

5 0
2 years ago
An I/O-bound program is one that, if run alone, would spend more time waiting for I/O than using the processor. A processor-boun
Lelechka [254]

Answer with Explanation:

An I/O-bound the programs that are used relatively a little processor times and are favored by an algorithm. However, if the processor bound process is denied the processor time for the sufficiently long periods of times, the same algorithms will be granted a processor to the process and it has not use the processors at all in recent pasts. Therefore, the processor bound process will not be the permanently denied to access.

3 0
2 years ago
Other questions:
  • Brianna would like to use a small program within the database to simplify the complicated task of creating a report. She should
    13·1 answer
  • Which of these is an advantage of using the Clipboard task pane? A. You are able to apply OLE easily. B. There are more paste op
    15·2 answers
  • What does a sticky CTA do?
    9·2 answers
  • A major weakness of a lot of file processing systems is that ____.
    10·1 answer
  • RFID tags are used in secure environments primarily due to the fact they are impossible to counterfeit.
    5·1 answer
  • Refer to the exhibit. Which two network addresses can be assigned to the network containing 10 hosts? Your answers should waste
    7·1 answer
  • Match common encryption algorithms and methods with the scenarios representing real-world business applications and requirements
    14·1 answer
  • Design and document an IP addressing scheme to meet ElectroMyCycle’s needs. Specify which IP address blocks will be assigned to
    11·1 answer
  • How many times is the function wordScramble() called in the given program? public class WordScramble { public static void wordSc
    6·1 answer
  • #Write a function called "in_parentheses" that accepts a
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!