Zack creates a game using 1000 drink tumblers each tumbler comes with a lid. 1.
ID: 3624823 • Letter: Z
Question
Zack creates a game using 1000 drink tumblers each tumbler comes with a lid.1. First Zack goes through and takes the lid off all 1000 tumblers.
2. He then returns to the first tumbler and puts the lid back on every other one.
3.Then he returns to the first tumbler and checks every third one:
if the lid is off, he puts it back on the tumbler
if the lid is on, he takes it off the tumbler
4. He repeats the process for every fourth tumbler and lid, every fifth tumbler and lid, etc
5. At the end what tumblers have lids on them?
***Must use an array. Also, use an enumerated type that denotes the lid being on or off.
Explanation / Answer
// plz metion language name ..if ur posting a coding question ....
// here go ahead with u r code.
#include<iostream>
#include<conio.h>
using namespace std;
bool off=false;
bool on=true;
int main()
{
bool lid[1001];
// to set all lids to false NOTE: the first lid is number 0. The last lid is 99.
for (int i=1;i<1001; i++)
{
lid[i] = off;
}
// first student opens all lids.
for(int S=1; S<1001; S++)
{
for(int k=S; k<1001; k=k+S)
{
if(lid[k]==off) lid[k] = on;
else lid[k] = off;
}
}
for(int S=1; S<1001; S++)
{
if (lid[S] == on) {
cout << "lid " << S << " Open" <<endl;;
}
}
/* else {
System.out.println("lid " + S + " Close");
} */
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.