Programming contests

20 Programming Exercise for Beginners

January 1, 2019 12:00 AM – December 31, 2019 12:00 AM

Plus Sign

Create a program that draws a plus sign to the output. The plus sign consists of 9 pixels ordered in 3 rows and 3 columns. 4 pixels in the corners belong to the background, the others belong to the foreground. The program should use the console, where each pixel is represented by a single character. The background is represented by a dot, the foreground is represented by a lowercase “x”.

Input Specification

The input consists of two lines, each terminated by a newline character. The first line contains the width, the second line contains the height of a pixel measured in characters. Both of those numbers are between 1 and 10.

Sample Input

  1. 3
  2. 2
download as text file

Output Specification

The output contains 3 * height lines, each containing 3 * width characters and being terminated by a newline character.

Output for Sample Input

  1. ...xxx...
  2. ...xxx...
  3. xxxxxxxxx
  4. xxxxxxxxx
  5. ...xxx...
  6. ...xxx...
download as text file

Hints and Guide

The output must be generated line by line, hence, if you are planning to use iterations embedded into each other, then the outer one must generate the lines (as the rows of the image).

To make the algorithm flexible, we suggest you to create a two-dimensional array containing the picture: the characters of the plus sign with 3 rows and 3 columns. The method to draw the array to the output is now straightforward. To enlarge the picture, you have to draw each line “height” times, and each character in the line “width” times.

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019