For example, if n = 5
, the following pyramid is printed.
#
##
###
####
#####
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.
For example, when n = 5
:
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 andnum
!= 0
For example,
- when
num = 10
andn = 2
,result
should be100
- when
num = 3
andn = 3
,result
should be27
- when
num = 20
andn = 0
,result
should be1
Marks will be awarded only if a loop is used to achieve this. You may use whichever loop you'd like
Make sure to think about which circles should be drawn first
for (int i = 0; i < 200; i+=40) {
fill(0, 0);
stroke(0);
circle(width/2, height/2, i);
}
for (int n = 0; n < 10; n += 1) {
if (n % 2 == 0) {
print(n * n);
}
println(n + 3);
}