2015-10-19 HW-Loops

posted Oct 19, 2015, 9:21 AM by Samuel Konstantinovich   [ updated Oct 19, 2015, 4:12 PM ]
Practice Exercises:  (Complete all of this by Wed, have a digital copy on marge so I can check it)
Part I
1. Make a for loop and a while loop print the numbers 1 to 20 inclusive.
2. Change the loops(make copies, comment out the old ones) so that they print only the even numbers between 1 and 20, that is, 2 4 6 8 10 12 14 16 18 20.
3. Change the loops(make copies) so that they print those numbers divisible by 3, that is, 3 6 9 12 15 18.
4. Change the loops(make copies) so that they print the square of each odd number, that is, 1 9 25 49 81 121 169 225 289 361.
5. Change the loops(make copies) so that they print all 20 numbers with plus signs between them and a blank on either side, but with no plus sign at the end, that is, 
        1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20.
6. Change the loops so that they go through the odd integers (from 1 to 19), keeping track of the sum of these integers at each stage, and printing the sum at each stage, so the output should be: 
        1 4 9 16 25 36 49 64 81 100.
7. Change the loops so that they add up a series that starts with 1.0/3.0, and each term is 1.0/3.0 times the previous term. (The answer should be a little less that one-half. The series looks like 
        1/3 + 1/9 + 1/27 + 1/81 + ... + 1/59049
8. Change the loops so that they add up a series that has each term equal to 1/i^3: 
    1/1^3 + 1/2^3 + 1/3^3 + 1/4^3 + 1/5^3 + 1/6^3 + 1/7^3 + 1/8^3 + 1/9^3 + 1/10^
Or:
    1 + 1/8 + 1/27 + 1/64 + 1/125 + 1/216 + 1/343 + 1/512 + 1/729 + 1/1000.

Part II
Coding bat For Loops and While loop practice:
Click here for : Strings-2
Complete these 6 problems:
doubleChar 
countHi 
catDog 
countCode 
endOther 
xyzThere
Comments