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
You can use pen and highlighter tools to emphasize information on a slide during a PowerPoint presentation. These tools are avai
11111nata11111 [884]
C. slide show toolbar

7 0
3 years ago
Gathering information with your eyes is called
Ivahew [28]
Observing, Looking, Collecting, there are a few words for "gathering information with your eyes". 
4 0
3 years ago
Read 2 more answers
Assume the following variables are defined: int age; double pay; char section; write a single c instatement that will read input
JulsSmile [24]

Answer:

scanf("%d %lf %c", &age, &pay, &section);

Explanation:

To read the value in c program, the instruction scanf is used.

To read the integer value, use the %d format specifier in the scanf and corresponding variable name age with ampersand operator.

To read the double value, use the %lf format specifier in the scanf and corresponding variable name pay with ampersand operator.

To read the character value, use the %c format specifier in the scanf and corresponding variable name section with ampersand operator.

5 0
3 years ago
Which of these field types allows multiple, non-exclusive options?
AlexFokin [52]

Question:

Which of these field types allows multiple, non-exclusive options?

A. multi-part

B. checkbox

C. text

D. radio button

E. button

Answer:

The correct option is B) Checkboxes

Explanation:

Field types is a terminology often associated with Database Management.

A field type is often found in a data collection apparatus such a form. It's inherent quality or nature will determine the kind of data that it can collect.

Some field types allow for exclusive options. That is, in some data field types, it's impossible to select more than one option.

For example, a Button field type can only collect one type of value.

A Checkbox on the other can be configured to allow for multiple selections which may or may not be exclusive.

When working with Microsoft Access, for instance, you are required to select the name of the <em>field </em>and define the type of <em>field data.</em>

<em />

Cheers!

6 0
2 years ago
Yo I need to know where to find a ps4 for free or a very cheap price please
svetlana [45]
Download offer up from the apple store or play store and search that up there’s many good deals and sometimes comes with games and controls included for cheap!
8 0
2 years ago
Read 2 more answers
Other questions:
  • When a range of IP addresses is set aside for client devices, and one of these IPs is issued to these devices when they request
    14·1 answer
  • Which of the following topics is too broad for a 10-minute speech? A. classes offered in interior design B. the history of moder
    13·2 answers
  • With ______________, the cloud provider manages the hardware including servers, storage, and networking components. The organiza
    6·1 answer
  • Should charter schools allow cell phone use in class?
    15·2 answers
  • Use fuel with the _____________ rating recommended by your vehicle manufacturer. A ) Converter B) Emission C) Exhaust D) Octane
    9·2 answers
  • Write a Bare Bones program that takes as input two variables X and Y. (Again, assume these values are set before your program be
    10·2 answers
  • . ____________is/are the JSP ImplicitObject(s).sessionapplicationconfigAll of GivenNone of Given
    9·1 answer
  • Can someone start me off with a short 2 or 3 paragraphs about the pros and cons of Microsoft Word, and if you can recommend a si
    12·1 answer
  • What's the answer plssss​
    10·1 answer
  • Create a SELECT statement that returns the count, average, max and min of the invoices submitted by each vendor, who has submitt
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!