Skip to main content
ICT
Lesson A12 - Iterations
 
Main   Previous Next
 

LAB ASSIGNMENT A12.1 page 12 of 18

FunLoops

Background:

  1. Magic Square problem:

    1. Some perfect squares have unique mathematical properties. For example, 36 is:

      • a perfect square, 62
      • the sum of the integers 1 to 8 (1+2+3+4+5+6+7+8 = 36)
      • a “magic square” (any number that is both a perfect square AND equal to the sum of consecutive integers beginning with 1)

    2. The next magic square is 1225:

      • 352 = 1225
      • 1225 = sum of 1 to 49

    3. Write a method that prints the first n magic squares.

  2. Least Common Multiple (LCM) problem:

    1. Write a method that determines the Least Common Multiple of two integers. For example, the LCM of the following pairs:
      2, 3
      LCM = 6
      4, 10
      LCM = 20
      12, 15
      LCM = 60
      7, 70
      LCM = 70

Instructions:

  1. Find the first four magic squares. The first one is the integer 1.

  2. Find the LCM of the following pairs of values:

    15, 18
    40, 12
    2, 7
    100, 5

  3. Try finding the first 10 magic squares. This program will take so long that you can accurately time it. Experiment with this program by running it on computers with different clock speeds (number of megahertz).

  4. Append your output to the end of your source file as a comment and submit the file. Your output should look like the following:

    Magic Squares
    
     1: 1
     2: 36
     3: 1225
     4: 41616
    
    LCM (15, 18) = 90
    LCM (40, 12) = 120
    LCM (2, 7) = 14
    LCM (100, 5) = 100
    
    Magic Squares
    
     1: 1
     2: 36
     3: 1225
     4: 41616
     5: 1413721
     6: 48024900
     7: 1631432881
     8: 55420693056
     9: 1882672131025
    10: 63955431761796
    11: 2172602007770041
    12: 73804512832419600
    13: 2507180834294496361

 

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.