Logo 
Search:

C Programming Article

Submit Article
Comments on Program to encode and decode given string
Category: C Programming (Homework Help)    Author: Easy Tutor

Write a program that encode and decodes user input string.


Vinay Vinny
Vinay Vinny from AustraliaOct 16
How to solve this problem?


You have n doors in a row that are all initially closed. You make n passes by the doors. The first

time through, you visit every door and toggle the door (if the door is closed, you open it; if it is

open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The

third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the nth door.

You need to find out what state are the doors in after the last pass? Which are open, which are

closed?

You'll be given number of doors, n.

You need to print out pair of (door_number, state) separated by '\n' aka 'end of line'. See

SAMPLE_OUTPUT for more clarity.

SAMPLE_INPUT:

3

SAMPLE_OUTPUT:

1,open

2,closed

3,closed


Please enter your Comment
  • Comment should be atleast 15 Characters.
  • Please put code inside [Code] your code [/Code].