Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Someone with c++ knowledge please help

Name: Anonymous 2011-03-09 0:46

Im using visual c++ 2008 express edition from microsoft

Write a program that reads in 16 values from the keyboard and tests whether they form a magic square when put into a 4x4 array. You need to rest two features :

-does each of the numbers 1,2,...,16 occur in the user input
-When the numbers are put into a square, are the sums of the rows, columns, and diagonals equal to eachother?

a magic square is when the sum of the elements in each row, column and in the two diagonals have the same value.

Name: Anonymous 2011-03-09 2:10

*
(define (magic-square? n0 n1 n2 n3 n4 n5 n6 n7 n8 n9 n10 n11 n12 n13)
    (define (proper-number? n)
      (and (>= n 1) (<= n 16)))
    (and (array? n)
         (andmap proper-number?
                 (list n0 n1 n2 n3 n4 n5 n6 n7 n8 n9 n10 n11 n12))
         (= (+ n0 n1 n2 n3)
            (+ n4 n5 n6 n7)
            (+ n8 n9 n10 n11)
            (+ n12 n13 n14 n15)
            (+ n0 n4 n8 n12)
            (+ n1 n5 n9 n13)
            (+ n2 n6 n10 n12)
            (+ n3 n7 n11 n13)
            (+ n0 n5 n10 n15)
            (+ n3 n6 n9 n12))))


Enjoy your troll ``LISP code'' without reading your ``SICP''.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List