[M-10]
Write a main()
program that
prints an n by n checkerboard made up of m by m squares. Here is a 24x24 checkboard
made of 6x6 squares:
******......******...... ******......******...... ******......******...... ******......******...... ******......******...... ******......******...... ......******......****** ......******......****** ......******......****** ......******......****** ......******......****** ......******......****** ******......******...... ******......******...... ******......******...... ******......******...... ******......******...... ******......******...... ......******......****** ......******......****** ......******......****** ......******......****** ......******......****** ......******......******
You can use this program to create image files that can be viewed with image processing programs. To do this, do not output "\n" at the end of each line (don't output anything at the end of a line). Change the two characters into '!' and '~'. These characters are at the beginning and at the end of the printable ascii characters. This increases the contrast between the dark and light squares. Now redirect the output of the program to a file:
C:\> check.exe > checkerboard.raw
If you have Adobe Photoshop you can open this file using the "raw" image format. In the raw image format, each byte of the file corresponds directly to a pixel in the image, and the file has no header or other information in it. You may have to tell Photoshop the size of your image.
Here is what Photoshop shows for a 256x256 raw image:
Most image viewers do not, unfortunately, support raw images. You may have an image viewer that supports "portable gray map" images, PGM. If this is the case, create the file as above but put the following as the first two lines:
P2 256 256 255
Each line ends with "\n". The P2 on the first line says that the image is in PGM format, the next line lists the number of columns, the number of rows, and the maximum gray level.
The program Irfanview will display RAW and PGM images and may others. www.irfanview.com.