Problem: Sunglasses

Write a program that takes an integer n (3 ≤ n ≤ 100) and prints sunglasses with size of 5*n x n as found in the examples:

Input Output Input Output
3 ******   ******
******   ******
4 ********    ********
*//////*    *//////*
********    ********
Input Output
5 **********     **********
*////////*     *////////*
*////////*     *////////*
**********     **********

Video: Sunglasses

Watch this video lesson to learn how to print sunglasses on the console using nested loops:

Hints and Guidelines

From the examples we can see that the sunglasses can be divided into three parts – upper, middle and lower one. A part of the code with which the problem can be solved is given below.

Printing the Top and Bottom Rows

When drawing the upper and lower rows we need to print 2 * n stars, n white spaces and 2 * n stars.

Printing the Middle Rows

When drawing the middle part, we need to check if the row is (n-1) / 2 - 1, because in the examples we can see that in this row we need to print pipes instead of white spaces.

Testing in the Judge System

Test your solution here:

results matching ""

    No results matching ""