CST1620 C# / C++ Programming
Lab Week 4


Exercises

Exercise 5.6  (Pythagorean Triples) (10 points)

A right triangle can have sides that are all Integers.  A set of three Integer values for the sides of a right triangle is called a Pythagorean triple.  These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse.  Write a program to find all Pythagorean triples for side1, side2, and the hypotenuse, all no larger than 500.  Use a triple-nested for loop that tries all possibilities.  The is an example of "brute force" computing.  Display your answers formatted nicely in a ListBox.

Hint: side a squared plus side b squared equals the hypotenuse squared in a right triangle.  So a2 + b2 = c2

  Result (Save to your local machine and run)

Note: Extra credit if you display the elapsed time for the program to compute the solution (4 points).

Comparison of execution times for the above exercise.

C# .NET
Visual Basic .NET
C++ .NET
C++ console
Visual Basic 6 compiled to native code
Java applet

Exercise 8.3  The milky way (10 points)

Write a program that draws 100 circles in a picture box at random positions and with random diameters up to 100 pixels.

Exercise 8.9  Fibonacci EC Extra credit (10 points)

The Fibonacci series is a series of numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, ...

Each number (except for the first two), is the sum of the previous two numbers.  The first two numbers are 0 and 1.  (Actually the material I find on the web contradict this, some say 0, 1 and some say 1, 1) The series is supposed to govern growth in plants.  Write a program to calculate and display the first 20 Fibonacci numbers starting with 0.

Interesting link on the Fibonacci series in layman terms.
This is a scholars point of view on the series.

  Result (Save to your local machine and run)

Exercise 8.10  Sum of series (10 points)

Write a program to calculate and display the sum of the series:

1 - 1/2 + 1/3 - 1/4 + ...

until a term is reached that is less than 0.0001.

  Result (Save to your local machine and run)