Programming Exercises

  1. Write a recursive program to compute the sum of the first n numbers


    
    
    

    (ex_rec_1)

  2. Write a recursive program to compute the pow of a number.


    
    
    

    (ex_rec_2)

  3. Pascal’s triangle is a number triangle with numbers arranged in staggered rows such that

    \[a_{nr} = {n! \over{r! (n-r)!}}\]

    This equation is the equation for a binomial coefficient. You can build Pascal’s triangle by adding the two numbers that are diagonally above a number in the triangle. An example of Pascal’s triangle is shown below.

            1
          1   1
        1   2   1
      1   3   3   1
    1   4   6   4   1
    

    Write a program that prints out Pascal’s triangle. Your program should accept a parameter that tells how many rows of the triangle to print.


    
    
    

    (ex_rec_13)

Next Section - Strings as collections of characters