samedi 13 novembre 2010

RAMZ I programm APL/FORTRAN

A magic square is a numeric matrix which the sum of values of each line, and the value of each column and each onr of rhe both main diagonals is a constant, we can write a monadic function " magic" who verify if his argument is a magic square.
here is a program  APLwritten by Robert caillot, marcel Dupras, claire Girard of the university of LAVAL canada.:

APL
v resul ---- magique   c; sum
[1]    A    cette fonction verifie si son
[2]    A    argument est un carré magique
[3]    A    C : matrice carrée de type numerique
[4]    A    SOM : somme des valeurs de la premoère ligne
[5]    A    RESUL : BOOLEAN caut 1 ssi C est un
[6]                          carré magique et 0 autrement
[7]    A                                                                      -
[8]    TCARRE : ------ CNCARRE    si  (1|¤C) =/=   1 | ¤C
[9]    CCARRE: C---- (¤C), [1] (C,[1], 1 /O/ C ), [1], 1¤¤C
[10]  RESOL --- ^/(1|SOM) = SOM++/C
[11]  ---- FT CARRE
[12]  CNCARRE : ' l'' argument ' n''est pas un carré magique'
[13]  FTCARRE :
[14] v

FORTAN

      j = (N+1)/2
C    rangement du premier terme = 1
      C(I,J) = 1
C   construction du carré
      M= N**2
      DO 2 K = 2,M
      J=J+1
C   test de depassement en colonne
      if (J,GT,N)J = 1
      I=I+1
C   test de depassement en ligne
      if(I,GT,N)I = 1
C   test de case occupée
     if(C(I,J),EQ,0) GOTO 2
C   case féja occupée
     J=J+1
     if (J.EQ0)J = N
     GOTO 4
2   C(I,J) = K
C   impression du tableau et calcul de la somme S
     S=0
     DO 3 I= N,1,-1
     S=S+C(I,J)
3   PRINT 5, (C(I,J),J=1,N)
5   FORMAT ( /25 I 5 )
     RETURN
     END

Aucun commentaire:

Enregistrer un commentaire