View the step-by-step solution to:

Question

A school has a specific number of lockers (up to MAX_LOCKERS) and specific number of students (up to

MAX_STUDENTS).

Let's assume it's 100 lockers (denoted L1 - L100) and 6 students (denoted S1 - S6).

All lockers are closed on the first day of school. Students can enter the locker room from the main entrance or back door.

The first student denoted S1 enters the locker room from the main entrance, starts from the 1st locker and opens every locker from 1st to 100th.

Then the second student S2 enters from the back door, starts from 2nd locker from the back (i.e. from 99th locker denoted L99), and closes every 2nd locker from the back: i.e. closes L99, L97, L95, ...

The third student S3 enters from the main entrance, stars from L3 (the third locker) and changes every 3rd locker (closes it if it was open, and opens it if it was closed), i.e. changes L3, L6, L9,...

The fourth student S4 starts from 4th locker from the back (i.e. L97) and changes every 4th locker from the back. I.e. changes L97, L93, L89, ...

The fifth student S5 starts from L5 and changes every 5th locker, i.e. changes L5, L10, L15, ...

The sixth student S6 stars from L95 and changes every 6th locker from the back, i.e. changes L95, L89, L83, ...

After all the students have passed through the building and changed the lockers, which lockers are still open? You program should answer this question for any number of students and lockers!


Output:

Input number of lockers (1-100): -5

Incorrect input. Please try again!

Input number of lockers (1-100): 85

Input number of students (1-100): 101

Incorrect input. Please try again!

Input number of students (1-100): 56

The school has 85 lockers and 56 students

Open lockers: 1, 6, 9, 10, 12, 20,...here will be numbers..., 83, 84, 85.


Main Requirements:

1. program in C to get number of lockers and student from console and display all open locker numbers separated by coma and exactly one space (see Demo Run).

2. You must define maximum allowed number of lockers and students using #define: #define MAX_LOCKERS 100 #define MAX_STUDENTS 100

3. Do NOT use scanf() function. You must use fgets() function + integer conversion. The input from console can be up to maximum value defined in Requirement N2. Hint: see Exercise 2.5 how MAX_SIZE was used on lines 4 and 12. Your program must work correctly when you change MAX_LOCKERS or MAX_STUDENTS values - see Hint N4. Sheridan College Page 3 of 4 PROG20799: Assignment N1 Winter 2020

4. You need to use array of Booleans lockers[MAX_LOCKERS]. See stdbool.h In the Boolean array lockers[i] the value "true" means the locker is open. Initially, all lockers are closed. You should have: bool lockers[MAX_LOCKERS] = {false}; Note: if lockers[i] is true, then (i+1)-th locker is open. See also Hint N5.

5. Program output should match the demo run! In the output you must use commas "," and there should be a dot "." at the end.

6. Your solution should have proper data types and optimal time and space complexity (minimize number of loops, variables, statements and expressions, reduce the number of function calls, use correct statements, etc) - See Hints N1-N3.


Must run in C!

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Object-Oriented Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors