This is easy. Lets define the state of the locker as open or closed. At any given point in time we know that a locker will be in one of these two states. Lets say we denote open state by 1 and closed state by 0. so we have to print all the lockers with open state which is 1 at the end of the task. We can do this in the following way.
Code :
#include <iostream>
using namespace std;
int main() {
//set all lockers state to closed
int lockers[101]={0};
for(int i = 1;i<=100;i++){
//we will start from ith locker for ith student
for(int j=i;j<=100;j=j+i){
//toggle the state of the lockers
lockers[j]=1-lockers[j];
}
}
for(int i =1;i<=100;i++){
if(lockers[i]==1){
cout<<i<<" ";
}
}
cout<<endl;
return 0;
}
OUTPUT :
1 4 9 16 25 36 49 64 81 100
I need help writing a program for this assignment Problem: Locker puzzle A school has 100...
JAVA PLEASE Concepts tested by this program: Variables Input/output .Loops Conditional Statements Methods . Arrays . Multi-Dimensional Arrays Program 1: Locker Puzzle Problem Description: A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker. Student S3 begins with the third locker and changes...
The Lockers Problem There is a well-known mathematical logic problem called the lockers problem. Here is a description of the problem 23 24 25 26 A new high school has just opened! There are 50 lockers in the school and they have been numbered from 1 through 50. When the school opens the first student to enter the school walks into the hallway and opens all the locker doors! Afterwards, the second student closes each door whose number is a...
Hi, I need help in solving Python programming problem below: Thank you. Best Regards When John gambles at the casino, he always uses a special system of tactics that he devised himself. It's based on always betting in one of two ways in each game: • betting exactly one chip (to test his luck); • betting all-in (he bets everything he has). Wins in the casino are paid equal to the wager, so if he bets C chips and wins,...
I need help making my debits and credits equal to $20,743. Amount Name Bive Raiderndventure park ndusted Tool Bouane DORT 8810 Laansa capital credit casni MONIS OCCOLTO Interest payadio $7000 10,000 Equipiant 420 360 2,100 Vrtinc pens 250 Aunis pavadi Insurance expanso 1605 Wagas expenso 380 Uncamca ratno CC HVITY Covinces 5650 mawing expenses SUPPS M. Tannskuwrindrawan 100 can Ticket verenver Accumulated Depreciation Sign Accumulated Depreciation Achustyc Jacumulated Depuccion-Equipment 495 Prepaid Insurance 100 Thierest expenso Depreciation expenso NOTES Rivaba Blue...
can someone help with the blue reader project, please? I have the journal entries I need help with journal ledger and trial balance so I can I do the financial statements. thanks can someone help me the ledger and trial balance please, I posted all the information about the picture Credit The accounting cycle illustrated below is designed to provide information about a company's profitability for lack thereof) along with many other important financial characteristics. This same accounting Cycle is...