Docsity

Analyzing Magic Squares: Determining Magic Constants and Completing Incomplete Ones, Prove d'esame di Computer Graphics

Toggle sidebar
bg1
Computer Sciences – 18/02/2016 – Total time: 2h
SURNAME:
NAME:
C1
STUDENT ID:
TEACHER:
Question 1
Given the integer number 4096, determine the minimum number of bits required to represent it as an unsigned
pure binary number.
Question 2
A computer system bus consists of an 8-bit Address Bus and a 32-bit Data Bus. Determine the maximum size of
the memory in megabytes (MB) that can be controlled using the mentioned bus.
Question 3
Explain, what is the role of the RAM memory in a microprocessor?
pf2

Anteprima parziale del testo

Scarica Analyzing Magic Squares: Determining Magic Constants and Completing Incomplete Ones e più Prove d'esame in PDF di Computer Graphics solo su Docsity!

Computer Sciences – 18/02/2016 – Total time: 2h

SURNAME: NAME:

C

STUDENT ID:

TEACHER:

Question 1

Given the integer number 4096, determine the minimum number of bits required to represent it as an unsigned pure binary number.

Question 2

A computer system bus consists of an 8-bit Address Bus and a 32-bit Data Bus. Determine the maximum size of the memory in megabytes (MB) that can be controlled using the mentioned bus.

Question 3

Explain, what is the role of the RAM memory in a microprocessor?

Computer Sciences – 18/02/2016 – Total time: 2h

Question 4 (PROGRAMMING) A “magic square” is defined as an arrangement of positive integer numbers placed in a 3x3 square matrix. In such a matrix, the numbers in the same row, in the same column, and in the first and second diagonals, all add up to the same number; this number (the result of the rows/columns/diagonals additions) is called the “magic constant” or “magic sum”. Examples of magic square:

1 8 3 12

Whichever row/column/diagonal sum gives the same result, magic constant = 12

Whichever row/column/diagonal sum gives the same result, magic constant = 111 Write a C program able to analyze an incomplete magic square contained in a file, which name is passed using the command line as the first parameter. Every line in the file contains 3 integer values separated by only one space, the provided file contains an incomplete magic square, i.e., one element is missing, and this value is replaced by -. Assume that the file content is correct, and in addition:

  1. There is only one missing value (i.e., only one value in the file is replaced by -1)
  2. The missing value is placed in one of the three positions in the first diagonal (0,0)-(1,1)-(2,2).

The program shall:

  1. Determine, by analyzing the content of the square (i.e., the entire rows/columns/diagonals additions but the ones including the missing value), if it seems possible to attempt to transform the given square into a magic square, by replacing the -1 value. In details, the program must check for all the rows/columns/diagonals additions containing all the three values, if the addition results produce the same value.
  2. If so, the program prints to the screen the magic constant computed using the file content.
  3. Calculate the value that replaces the missing one (-1) converting the square into a magic square: a. If this value exists, display the square completed with the calculated value. b. Otherwise, indicate that it is impossible to complete the magic square. Examples of execution:

EX. 1 8 1 6

EX. 2

It seems POSSIBILE to try to complete the magic square.

It is NOT POSSIBLE to complete the magic square. Magic constant = 15.

8 1 6 3 5 7

4 9 2

EX. 3

It seems POSSIBILE to try to complete the magic square. Magic constant = 110. IMPOSIBLE to complete the magic square.