PF Assignmnet 2
PF Assignmnet 2
ASSIGNMNET
INSTRUCTIONS:
Please keep the following in mind:
• Do not share your code with anyone else. All assignments are to be done
individually.
• SOLUTIONS/PLAGIARISM from INTERNET will lead to ZERO
• You must submit the .c files only. Make sure you name as
rollno_name_dept_sec.cpp
• For example: P22_1234_ Name_CS_1D
• Make sure you follow the naming schemes of the .c files correctly. Failure
to do so will result in getting ZERO.
• No submissions other than Classroom will be entertained.
• Make sure your code compiles and runs. If a piece of code fails to compile,
you’ll be given a ZERO.
• All submissions will be checked for plagiarism. You are not allowed to copy
code from the internet or any other individual.
• Any sort of plagiarism will lead to ZERO.
• DO NOT MODIFY FILE, JUST WRITE YOUR CODE IN DESIRED AREA.
• RENAME task.c according to this schema P22_1234_Name_CS_1D
• ARRAYS are not allowed.
• USE ONLY LOOPS and FUNCTIONS
• LATE SUBMITIONS WILL NOT BE ENTERTAINED
• DEADLINES TO BE FOLLOWED STRICTLY
Page 1|3
CS118 Programming Fundamentals (Fall 2022)
A high school has “n” number of students and “m” number of lockers. For
simplicity we are taking 100 students and 100 lockers. On the first day of school,
the principal plays the following game: She asks the first student to go and open
all the lockers. She then asks the second student to go and close all the even-
numbered lockers. The third student is asked to check every third locker. If it is
open, the student closes it; if it is closed, the student opens it. The fourth student
is asked to check every fourth locker. If it is open, the student closes it; if it is
closed, the student opens it. The remaining students continue this game. In
general, the nth student checks every nth locker. If the locker is open, the student
closes it; if it is closed, the student opens it. After all the students have taken their
turn, some of the lockers are open and some are closed. Your job is to tell how
many lockers are open at the end of the game and if we take 100 students and
100 lockers the result should be 10.
1.1 Tasks to do
Note: Please make sure your functions are defined before Main and test1 and
test2 Functions
Page 2|3
CS118 Programming Fundamentals (Fall 2022)
Hint: Try to do yourself. Try to break it into smaller parts and make function.
Page 3|3