Homework Assignment

For Loops

Overview

Topic: For Loops
Related Reading: Chapter 7
Due:

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

  1. (10 points)

    Write a program that allows the user to enter a nonnegative integer $k$ and returns the sum of the first $k$ perfect squares, $$\sum_1^k{k^2}.$$ For example, if $k=4$ the sum should be $1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + 9 + 16 = 30$. A sample execution might appear as

    Enter k: 4
    30

  2. (10 points)

    Ask the user for a word and then output the following pattern.

    Enter word: example
    e
    ex
    exa
    exam
    examp
    exampl
    example
    

Last modified: Wednesday, 26 September 2018