Functions that are nice to program

1.  Write a function that adds up the whole numbers from 1 to n.  For example the sum form 1 to 10 is 55.   The formula , developed by Carl F. Gauss, is  SumN(n)= n(n+1)/2

2.  The area and volume of a icosahedron can be found here. Can you say Adenovirus or radiolaria.   The other platonic solids are here.   The Archimedean solids are also interesting.

3. You may recall that if you have two points on a plane (x1,y1) and (x2,y2) you can calculate the distance between them using the formula d=sqrt((x2-x1)**2 +(y2-y1)**2)

4.  Remember the quadratic formula for solving 0=ax2+bx+c.  Look it up.  Remember there are two answers and they may be real or imaginary.

5.  Calculate the combination of N things taken r at a time.  Cn,r = n!/(r!(n-r)!)

6.  The area of a triangle can be calculated by Herons formula.  Here is a discussion.

7. Write two functions called even(n) and odd(n).  These use the modulo operator % to return either true or false.  IE even(n) should return true if n is even otherwise return false.  Note a simple comparison such as x>4 or z==3 are either true or false.  The % operator returns the remainder after dividing.  For example x % 2 will return either a 0 or a 1.

8.  Write a function called PerfectSquare(n) that will return true or false depending on whether or not n is a perfect square.  Examples ae 1,,4,9,16,25 and so on.   This one is a little tricky.

9.  Write a formula that will calculate and return compound interest.  Here is a discussion.

10.

This entry was posted in Algorithms. Bookmark the permalink.

Comments are closed.