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
Budget Analysis (use while loop) Write a program that asks the user to enter the amount that he or she has budgeted for a month.
Agata [3.3K]

Answer:

print('This program will help you determine whether you\'ve budgeted enough ' +

     'for your expenses. You\'ll just need to enter your budget and the ' +

     'cost of each of your expenses for the month and we will calculate ' +

     'the balance.')

budget = float(input('How much have you budgeted this month? '))

expenses = 0

check = 0

while check >= 0:

   check = float(input('Enter an expense amount or -1 to quit: '))

   if check != -1:

       expenses += check

balance = budget - expenses

if balance < 0:

   print('\nYou haven\'t budgeted enough. You\'re going to be $', \

         format(-1 * balance, ',.2f'), ' short this month.', sep = '')

elif balance == 0:

   print('\nBe careful. You\'ve budgeted just enough to make it through ' +

         'the month.')

else:

   print('\nYou will have $', format(balance, ',.2f'), ' extra this month.', \

         sep = '')

6 0
1 year ago
Krista needs to configure the default paste options in PowerPoint 2016. Which area of the Options dialog box will she need to us
Vikki [24]

Answer:

Advanced

Explanation:

Advanced pane in the PowerPoint Options dialog box contain less commonly used PowerPoint options such as Editing options, Cut, copy, and paste, Pen, Image size and quality, Chart options, display and many more.

By default, In powerpoint you paste content into a document using CTRL+V, the Paste button, or right-click + Paste. To configure the default paste options in PowerPoint 2016 follow these steps:

  1. Go to File > Options > Advanced.
  2. Under Cut, copy, and paste, select the down arrow for the setting to change.
  3. Click OK
5 0
2 years ago
Which of these are characteristics of a Python data type? Check all that apply.
Lorico [155]

Answer:

A Python data type is weakly typed.

A Python data type can have numeric values.

A Python data type can be shown by keys and values within brackets [ ].

A Python data type can be a string, a list, or a tuple with items that can be repeated using the asterisk ( * ).

A Python data type can be a dictionary that can be updated, changed, or removed.

Aka A B C E F

4 0
2 years ago
How can a signature be added to an email message? Check all that apply.
lara [203]

Answer: im not sure you should just you tube it

Explanation:

You tube can teach you a lot of things you just need to use it

5 0
1 year ago
Read 2 more answers
What are threats to computer system
Readme [11.4K]
Theft or vandalism through to natural disasters are physical threats. Non-physical threats target the software and data on the computer systems, Like hackers or just straight up viruses. Also, untrustworthy apps or games can give your computer viruses as well.
3 0
2 years ago
Other questions:
  • Blender questions
    8·2 answers
  • During which phase of web publishing would you use a text editor to enter codes that instruct the browser how to display webpage
    5·1 answer
  • In which of these places might you be most likely to find a peer-to-peer network? On the Internet In a hospital In a home In a l
    5·2 answers
  • Write a method called printReverse that accepts a String as its parameter and prints the characters in opposite order. For examp
    9·1 answer
  • Which of these statements regarding mobile games is true? A. They are typically played indoors. B. They have detailed environmen
    7·1 answer
  • Create a generic class Box with a type parameter that simulates drawing an item at random out of a box. This class could be used
    7·1 answer
  • (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o
    10·1 answer
  • Performing binary search on an unsorted list will always return the correct answer in O(n) time where n is the length of the lis
    9·1 answer
  • Which statement is true about the purpose of a work in process constraint?
    15·1 answer
  • What are ways to enter a formula in Excel? Check all that apply. Click on the Function Library group and select a function from
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!