Matrix with two diagonals: Difference between revisions

Line 1,047:
 
=={{header|Fortran}}==
===Free form===
{{works with|Fortran 95}}
Fortran stores data in columns. Therefore, it should be checked whether instead of filling the matrix row by row (as below) it would be better to do it column by column. The profit would be cache hit optimization, better communication between CPU and RAM. Fortran allows you to zero the entire array, such as the a array below, simply by substituting a = 0. Unfortunately, an array 100x100 (that is, the choosen maximum size) would be filled with zeros even if, as in the example, we would need a much smaller array. You can also eliminate the variables j1 and j2 by replacing them with i and n - i + 1 respectively, but the source code would be slightly less readable.
Line 1,083 ⟶ 1,084:
1.00000000 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 1.00000000
</pre>
===Fixed form===
{{Works with|gfortran --std=legacy}}
<lang fortran>C DIAGONAL-DIAGONAL MATRIX IN FORTRAN 77
 
PROGRAM PROG
DIMENSION A(100, 100)
N = 7
 
A = 0.
DO 10 I = 1, N
A(I, I) = 1
10 A(I, N - I + 1) = 1.
DO 20 I = 1, N
20 PRINT *, (A(I, J), J=1,N)
END</lang>
 
=={{header|Go}}==