Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 2.09 KB

05 - L Basic.md

File metadata and controls

85 lines (57 loc) · 2.09 KB

✨ L Basic ✨

Use a loop to print a right half pyramid pattern of size n:

For example, if n = 5, the following pyramid is printed.

#
##
###
####
#####

Given a size, n, write a loop to print a right half pyramid with incrementing digits on each line.

For example, if n = 4, the following pyramid is printed.

1
1 2
1 2 3
1 2 3 4

Note that the digits on each row are separated by spaces.

Given a positive integer n, use a loop to calculate the factorial of n.

For example, when n = 5:

Recreate the following image using a loop:

loopLines.png

Given two floats num and n, use a loop to calculate num to the power of n and store it in a variable called result

Assume that n >= 0 and num != 0

For example,

  • when num = 10 and n = 2, result should be 100
  • when num = 3 and n = 3, result should be 27
  • when num = 20 and n = 0, result should be 1

Recreate the following image using a loop:

loopSquares.png

Write a piece of code that displays the following pattern on the console.

Marks will be awarded only if a loop is used to achieve this. You may use whichever loop you'd like

1 4 9 16 25 36 49 64 81 100

Recreate the following image using a loop:

loopCircles.png

Use a loop to create the following image:

Make sure to think about which circles should be drawn first

dartBoard.png

Convert the following code to use a while loop instead of a for loop

for (int i = 0; i < 200; i+=40) {
    fill(0, 0);
    stroke(0);
    circle(width/2, height/2, i);
}

What would be the output of the following code?

for (int n = 0; n < 10; n += 1) {
	if (n % 2 == 0) {
		print(n * n);
	}
	println(n + 3);
}