CS 2500 Fall 2005
Lab Assignment 1
Due 09/20/05

Solve the following exercises using C++:

1. Write a program which reads a positive integer N and calcualtes the sum of the first N odd integers. E. g., if N is 4 then the program should produce the number 16 (1+3+5+7).

2. The German mathemetician Leibniz discovered that the constant pi can be computed using the following relationship:

pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + .....

Write a program which computes an approximation of pi by summing the first N terms of the series (where N is a number read from the keyboard)> Thus if the input number N is 4, the program should compute  1 - 1/3 + 1/5 - 1/7 (the first four terms of the series.

3. Greek mathematicians defined the concept of perfect numbers. A number N is perfect if N is equal to the sum of all its proper divisors (i.e. all divisors of N, except N itself). For example, 6 is a perfect number since its proper divisors and 1,2,, and 3 and 1+2+3 = 6. On the other hand, 8 is not a perfect number, since its proper divisors are 1,2, and 4, but 1+2+4 = 7.

Write a function which takes a positive integer and returns whether the number is perfect. Then write a program which will compute all perfect numbers between 1 and 10,000, making use of the function.