IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

eXercise #9

Iteration using FOR...DO

  1. Write short programs using FOR..TO..DO loops to print the following output:

    1. abcdefghijklmnopqrstuvwxyz

    2. zyxwvutsrqponmlkjihgfedcba

    3. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    4. 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30

    5. 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225

    6. 1024 512 256 128 64 32 16 8 4 2 1


  2. The sum of all the numbers from 1 to 100.

  3. The sum of the squares of the numbers from 1 to 10.

  4. Use a for loop to write out 100 random numbers between 0 and 99, 20 to a line. At the end of this output, the sum and the average of the numbers should also be printed.

  5. HOW RANDOM IS RANDOM
    Write a program that generates 100 random numbers between 0 and 5, tallying the number of 0's, 1's .. 5's, then outputting the results in graph form as such:
    0: ***********************
    1: ************************
    2: ******************
    3: ***********
    4: *********************
    5: *****************
    
Experiment with bigger numbers - if the random number generator is good, there should be equal numbers of each value generated.

Solutions

wonko@wonko.info
©Copyright t 1992..2018+. Edition 26.150117
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.