Алгоритмический язык PASCAL. Алфавит языка. Идентификаторы. Операции над данными, страница 14

WRITELN ( 'N-M=', N-M, '    (N-M)F=', NMF ) ;                             END.

Результат:

N=7         NF=5040

M=4         MF=24

N-M=3         (N-M)F=6

10. Пример  решения  задачи.

Пример:     Заполнить   матрицы  А(4,4), В(5,4), С(6,6).

Элементы матриц определить различными спосо-     бами:                          

- A(4,4) – по  формуле            

 , причем  при  делении  на  0  принять  значение   элемента, равным  1;                                            

- В(5,4) - принять случайными числами;                

- С(3,3) - задать  как  const  в  описании  типов.      

PROGRAM   MATR3;                                                  

USES  CRT, PRINTER;                                               

LABEL  10;                                                                  

CONST   C : ARRAY[1..3,1..3]  OF  INTEGER   =((2,3,4),(5,6,7),(8,9,1)); 

VAR   I, J : INTEGER;                                                

A : ARRAY[1..4,1..4]  OF  REAL;                                  

B : ARRAY[1..5,1..4]  OF  INTEGER;                              

BEGIN                                                            

CLRSCR;                                                         

WRITELN; WRITELN; WRITELN;                                                  WRITELN('                 МАТРИЦА А(4,4)');                    WRITE('    ЭЛЕМЕНТЫ  ОПРЕДЕЛЕНЫ  ПО  ФОРМУЛЕ ' );        

WRITELN;  WRITE('       ');                                               

FOR  I : = 1  TO  4  DO  BEGIN

FOR  J : = 1  TO  4  DO  BEGIN                                                                                 

IF   J -1 = 0  THEN  BEGIN   

A[I,J] : = 1;  GOTO  10;                                    

END;                                                    

A[I,J] : = 1+I*I / ((J-1)*(J-1));                                  

10:  WRITE(A[I,J] : 7 : 2 );                                         

END;

WRITELN; WRITE('       ');                                                                                        

END; 

WRITELN;                                                      

WRITELN('                 МАТРИЦА В(5,4)');                             

WRITE('        ЭЛЕМЕНТЫ – СЛУЧАЙНЫЕ  ЧИСЛА  ’);

WRITELN; WRITE('      ');                                     

FOR  I : = 1 TO  5  DO  BEGIN                                        

FOR  J : = 1 TO  4  DO  BEGIN                                        

B[I,J]:=RANDOM(100)-30;                                   

WRITE(B[I,J] : 7);                                          

END;                                                      

WRITELN;WRITE('      ');                                     

END;                                              

WRITELN;                                                     

WRITELN('                  МАТРИЦА  С(3,3)');                

WRITE('         ЭЛЕМЕНТЫ  ЗАДАНЫ В БЛОКЕ  CONST  ' );      

WRITELN; WRITE('      ');                                     

FOR  I : = 1  TO  3  DO  BEGIN                                        

FOR  J : = 1  TO  3  DO  BEGIN                                        

WRITE(C[I,J] : 7);                                          

END;                                                      

WRITELN; WRITE('      ');                                      

END;                                                         

END.                                                         

В  результате  выполнения  программы  получены матрицы:          

МАТРИЦА А(4,4)                     

ЭЛЕМЕНТЫ  ОПРЕДЕЛЕНЫ  ПО  ФОРМУЛЕ          

1.00     2.00    1.25    1.11

1.00     5.00    2.00    1.44

1.00   10.00    3.25    2.00

1.00   17.00    5.00    2.70 

МАТРИЦА В(5,4)                              

ЭЛЕМЕНТЫ – СЛУЧАЙНЫЕ  ЧИСЛА   

-30     -27      56     -10 

-3      37         1    -14

7      12      -22     17

-23      54      -25      -1

61        6        47       2

МАТРИЦА  С(3,3)                

ЭЛЕМЕНТЫ  ЗАДАНЫ В БЛОКЕ  CONST       

2       3       4

5       6       7