Modulus Tutorial

From Progzoo
Jump to: navigation, search

The modulus operator % gives the remainder when one number is divided by another.

Vertical Stripes

i % 2 gives 0 if i is even and 1 if i is odd.

Change the code so that the stripes are vertical.

BoxesVstripes.png
[Font] [Default] [Show] [Resize] [History] [Profile]

Spaced Stripes

Change the code so that the stripes are at 0, 4 and 8.

BoxesSpacedStripes.png
[Font] [Default] [Show] [Resize] [History] [Profile]

Grid

The grid shown has red if either i or j is an even number.

BoxesGrid.png
[Font] [Default] [Show] [Resize] [History] [Profile]

Chess board

Produce the checker board pattern shown.

BoxesChecker.png
[Font] [Default] [Show] [Resize] [History] [Profile]

Trailing diagonal stripes

Diagonal stripes.

BoxesTDStripes.png
[Font] [Default] [Show] [Resize] [History] [Profile]

Diagonal grid

Now we are just playing, stop this and move onto something less silly!

Diagonal grid.

BoxesDGrid.png
[Font] [Default] [Show] [Resize] [History] [Profile]