Homework 3
User-defined functions: Creating functions with more than one return value

Due: Tuesday, November 14, 2006 at 11:59pm

Outcomes

After successfully completing this assignment, you will be able to...

Before Starting

Read sections 6.9 and 7.1 - 7.4.

The Assignment

An n x n matrix of integers is called a magic square if all the rows, columns, and diagonals sum to the same value, and each integer value from 1 to n-squared appears exactly once in the matrix. The 5 x 5 matrix shown below is a magic square because each row, column, and diagonal sum to 65 and each of the integers from 1 to 25 appears exactly once:

         17   24    1    8   15

         23    5    7   14   16

          4    6   13   20   22

         10   12   19   21    3

         11   18   25    2    9
Write a C program that will ask the user to enter the values for a square array of size 10 x 10 or smaller and will verify whether the values do, in fact, form a magic square. The program should also print the sum of one of the rows if the square is a magic square.

Include files

Assumptions and Restrictions

The program must include the following functions: Other functions may be included if you wish. All functions must be commented with pre- and post-conditions.

Sample Execution

 You will be asked to enter the values in a square
 matrix.  This program will determine if the square
 is a magic square or not.  In a magic square, the
 sum of the integers is the same for every row, column,
 and diagonal, and each integer appears only once.


How many rows in your square?
3

Enter all the values in row  1 separated by spaces
8 3 4
Enter all the values in row  2 separated by spaces
1 5 9
Enter all the values in row  3 separated by spaces
6 7 2

 Here is your square

  8  3  4
  1  5  9
  6  7  2

The square you entered IS a magic square
The sum of each row is  15

Deliverables

Submit your implementation file using the following turnin command:

/cs/bin/turnin submit cs2301 hw3 hw3.c

Programs submitted after 11:59pm on November 14 will be tagged as late, and will be subject to the late homework policy.

Grading

This assignment will be graded on the following areas: documentation (including pre- and post-conditions for all functions), proper choice of parameters and local variables, proper choice of function return types, adherence to specifications for each function, correctness, and robustness (ability to recover from invalid input). Programs must compile successfully in order to receive points for correctness.