Course of Raku / Essentials / Loops / Exercises

Squares and cubes in a loop

Problem

Write a program that prints squares and cubes of the numbers between −5 and 5 inclusive. There should be three values on each line: the number itself, its square and its cube. Use a loop.

Example

The expected output of the program (assuming the loop goes from −3 to 3):

$ raku squares-and-cubes.raku
-3	9	-27
-2	4	-8
-1	1	-1
0	0	0
1	1	1
2	4	8
3	9	27

Solution

See the solution

Next exercise

💪 Factorial

Course navigation

Conditional checks / Ternary operator   |   Data type conversion