How to resolve the algorithm Write float arrays to a text file step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Write float arrays to a text file step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: The file should look like: This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Write float arrays to a text file step by step in the ALGOL 68 programming language
Source code in the algol programming language
PROC writedat = (STRING filename, []REAL x, y, INT x width, y width)VOID: (
FILE f;
INT errno = open(f, filename, stand out channel);
IF errno NE 0 THEN stop FI;
FOR i TO UPB x DO
# FORMAT := IF the absolute exponent is small enough, THEN use fixed ELSE use float FI; #
FORMAT repr x := ( ABS log(x[i])
repr y := ( ABS log(y[i])
putf(f, (repr x, x[i], $" "$, repr y, y[i], $l$))
OD;
close(f)
);
# Example usage: #
test:(
[]REAL x = (1, 2, 3, 1e11);
[UPB x]REAL y; FOR i TO UPB x DO y[i]:=sqrt(x[i]) OD;
printf(($"x before:"$, $xg$, x, $l$));
printf(($"y before:"$, $xg$, y, $l$));
writedat("sqrt.dat", x, y, 3+2, 5+2);
printf($"After:"l$);
FILE sqrt dat;
INT errno = open(sqrt dat, "sqrt.dat", stand in channel);
IF errno NE 0 THEN stop FI;
on logical file end(sqrt dat, (REF FILE sqrt dat)BOOL: stop);
TO UPB x DO
STRING line;
get(sqrt dat, (line, new line));
print((line,new line))
OD
)
You may also check:How to resolve the algorithm Take notes on the command line step by step in the Scheme programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the V programming language
You may also check:How to resolve the algorithm Even or odd step by step in the உயிர்/Uyir programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Batch File programming language