Assignment 3

Purpose

This program is intended to help you gain some experience using arrays in SAL.

Program Statement

Write a SAL program that reads in a value for the number of rows in a square array of integers. If the number of rows is size, the program should next read size*size integers into the array (one integer per line). Have the program echo print the array as a size-by-size table of integers.

If the values in every row, every column and both major diagonals each sum to the same value, print:

The array is a magic square.

Otherwise print:

The array is NOT a magic square.

A Sample Run (with user inputs in bold)...

Size? 3
Enter 9 integers:
integer 1? 8
integer 2? 1
integer 3? 6
integer 4? 3
integer 5? 5
integer 6? 7
integer 7? 4
integer 8? 9
integer 9? 2

The array is:

8  1  6
3  5  7
4  9  2

The array is a magic square.

Requirements

  1. Issue the prompts and other messages as indicated in the sample run.
  2. Echo print the array as indicated in the sample run. Put some space between the numbers to improve readability but don't worry about getting the colums to line up exactly.
  3. Print the correct message after you echo print the array.
  4. The value of size should be from 1 through 10, inclusive. If size is out of range, just issue the message "size is out of range" and exit the program.

Notes

  1. You may assume that exactly size*size integers follow size in the test input stream.

Handing In the Program

You must "hand in" your program (the SAL source code) to the computer directly by

cp p3.s ~cs354-1/handin/username/P3/.

just once, where "p3.s" is the name of the file containing your SAL source code. No printouts will be turned in. I will run your program several times using different test data.