Modulus Tutorial

From Progzoo

(Redirected from Tutorial/Boxes/Modulus)

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

Contents

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.

[Font] [Default] [Show] [Resize] [History] [Profile]

Spaced Stripes

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

[Font] [Default] [Show] [Resize] [History] [Profile]

Grid

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

[Font] [Default] [Show] [Resize] [History] [Profile]

Chess board

Produce the checker board pattern shown.

[Font] [Default] [Show] [Resize] [History] [Profile]

Trailing diagonal stripes

Diagonal stripes.

[Font] [Default] [Show] [Resize] [History] [Profile]

Diagonal grid

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

Diagonal grid.

[Font] [Default] [Show] [Resize] [History] [Profile]