Lab 6. Loops



Program 1: Factorial

Write an application that calculates a factorial.

The factorial of a number is the product of all integers from 1 to the number. For example, the factorial of 5 is 1 * 2 * 3 * 4 * 5 which equals 120.

You will need the following:

You should enter the code to do the calculation and produce the output within the button's click event function.

Writing the code:


Program 2: Power To

Write an application that calculates x^y or x to the power of y.

x to the power of y is x multiplied by itself y times. For example, 3 to the power of 4 is 3 * 3 * 3 * 3 which is 81.

You will need the following:

You should enter the code to do the calculation and produce the output within the button's click event function.

Writing the code:

Suggested algorithm

      Declare and initialize variables to appropriate values
      If power is negative
         Construct msgbox with error message
      Otherwise
         Loop power(y) times
            product = product * base(x)
         Next
         Output final product to label
      End if

Program 3: Night Sky

Write an application that draws the stars and a crescent moon in a picture box.

Draw this to a picture box the same way you did the smiley in the last lab. This time, however, you will use a for loop to randomly draw 200 stars.

You will need the following:

You should enter the code to draw the stars and moon within the picture box's click event function.

Writing the code:


Bonus: Up to 20% possible

Draw a random lightening bolt to your night sky using a For loop.