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]
1 year 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]1 year 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
Cooper Technologies is a technology company that offers many IT services in Chicago. The company's services and products include
yuradex [85]

Answer:

d. broad needs and few customers.

Explanation:

This strategy is based on creation of unique and valuable persons.

Broad needs and few customers (Wealth Management )

Wealth management is a service that combines to address the needs of clients. Wealth Management utilizes financial discipline such as financial and investment , accounting and tax.This service is appropriate for individuals with broad array of diverse needs.

4 0
2 years ago
Someone claims that the big O notation does not make sense at all, and they give the following example. An algorithm A that proc
Svetllana [295]

Answer:

Big Oh notation is used to asymptotically bound the growth of running time above and below the constant factor.

Big Oh notation is used to describe time complexity, execution time of an algorithm.

Big Oh describes the worst case to describe time complexity.

For the equation; T(N) = 10000*N + 0.00001*N^3.

To calculate first of all discard all th constants.

And therefore; worst case is the O(N^3).

7 0
2 years ago
A sum amounts to ₹2400 at 15% simple interest per annum after 4 years fond the sum.​
Elis [28]

Answer: $1,500

Explanation:

The future value of value using simple interest is:

Future value = Value * ( 1 + rate * time)

2,400 = Value * (1 + 15% * 4)

2,400 = Value * 1.6

Value = 2,400 / 1.6

Value = $1,500

6 0
1 year ago
Memory is a _____________ that includes the organization and shaping of information by processing, storage, and retrieval of inf
vaieri [72.5K]

Answer:

A. <em>Encoding Process </em>

Explanation:

Memory is an <em>encoding process </em>that includes the organization and shaping of information by processing, storage, and retrieval of information.

There are two types of memory in computing, <em>RAM </em>and <em>ROM</em>. <em>RAM </em>stands for <em>Random Access Memory</em>. It I the core memory of the computer and it is especially faster regarding reading and writing process. As an analogy, RAM memory is like the “<em>Short-term</em>” memory of the computer. <em>ROM </em>stands for <em>Read-Only Memory</em>, this is the type of memory in charge of permanently storing data in the computer. It contains the necessary information to run the computer. As an analogy, <em>ROM </em>memory is like the “<em>long-term</em>” memory of the computer.

3 0
1 year ago
Two blue armies are each poised on opposite hills preparing to attack a single red army in the valley. The red army can defeat e
labwork [276]

Answer:

I would attack with one blue army and while all the chaos I would send the foot soldier to the second blue army and tell them to attack with the first. Idk like if the foot soldier is the only way of communication, so yeah

6 0
2 years ago
Read 2 more answers
Other questions:
  • In three to five sentences, explain how you would insert graphics using your word-processing software.
    7·2 answers
  • Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
    6·1 answer
  • Most GUIs provide all of the following except _____.
    12·2 answers
  • _____ is the process of adjusting colors in an image.
    13·2 answers
  • A company wants to publish Knowledge articles to its Customer Community. The articles should be organized for easy navigation by
    6·1 answer
  • int) You are the head of a division of a big Silicon Valley company and have assigned one of your engineers, Jim, the job of dev
    8·1 answer
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    13·1 answer
  • Jen is trying to discover if a motor has failed windings. What sort of test can she do.
    6·1 answer
  • While Angela is making modifications to Katie’s Word document, she would like to inform Katie of the reasoning for the change. W
    10·1 answer
  • Put the steps in order to produce the output shown below. Assume the indenting will be correct in the program.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!