Suppose that a row of mailboxes are numbered 1 through 150 with 10 mailboxes on
ID: 3638251 • Letter: S
Question
Suppose that a row of mailboxes are numbered 1 through 150 with 10 mailboxes on each row. Beginning with mailbox 2, we open the doors of all the even-numbered mailboxes. Next, beginning with mailbox 3, we go to every third mailbox, opening its door if it is closed and closing it if it is open. We repeat this procedure with every fourth mailbox, then every fifth mailbox, and so on. Using an array to model the mailboxes, write a program to determine which mailboxes will be open when this procedure is completed.here's what i have so far:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define SIZE 150
int main (void)
{
int mailbox[SIZE]={0};
int i,j;
for (i=1; i<SIZE;i++)
for (j = 2; j <= SIZE; j+=2)
{
for (i = j; i <= SIZE; i += j)
{
if (mailbox[i] == FALSE)
mailbox[i] = TRUE; // open mailbox
else
mailbox[i]= FALSE; // mailbox closed
}
}
printf("%i", mailbox[SIZE]);
getch();
return 0;
}
Explanation / Answer
#include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.