This is a review catch-your-breath project. You will write three similar programs. The first program will calculate the sum of the numbers from 1 to 100, the second program will calculate the product of all the numbers from 1 to 10 (10 factorial), and the third program will calculate the sum of the square root of each number from 1 to 100.
In each case you will want to use an accumulator and a loop. An accumulator
is a variable that holds the answer so far. It usually has a name like sum
or product
or total
. If we use the name foo
, the psuedocode looks like
this:
declare and initialize foo
for i in 1 to 100
add the old value of foo and i, and store the answer in foo
print foo (the answer)
You will of course adapt this psuedocode accordingly for the product and sum of square roots programs.
You can take the square root of a number with the sqrt
function in the math
library (you will need to #include <math.h>
). For more information type man
3 sqrt
.
Use this makefile for the project (save it as Makefile
), and
name your files sum.c
, product.c
, and sum_of_sqrt.c
.