Babbage problem: Difference between revisions
Content added Content deleted
No edit summary |
(Added Algol 68) |
||
Line 16: | Line 16: | ||
The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem. |
The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem. |
||
<br><br> |
<br><br> |
||
=={{header|ALGOL 68}}== |
|||
As wih other samples, we use "simple" forms such as "a := a + 1" instead of "a +:= 1". |
|||
<lang algol68>COMMENT text between pairs of words 'comment' in capitals are |
|||
for the human reader's information and are ignored by the machine |
|||
COMMENT |
|||
COMMENT Define s to be the integer value 269 696 COMMENT |
|||
INT s = 269 696; |
|||
COMMENT Name a location in the machine's storage area that will be |
|||
used to hold integer values. The values could be larger than the |
|||
machine's default maximum value. |
|||
The value stored in the location will change during the |
|||
calculations. |
|||
Note, "*" is used to represent the multiplication operator. |
|||
":=" causes the location named to the left of ":=" to |
|||
assume the value computed by the expression to the right. |
|||
"sqrt" computes an approximation to the square root |
|||
of the supplied parameter |
|||
"MOD" is an operator that computes the modulues of its |
|||
left operand with respect to its right operand |
|||
"ENTIER" is a unary operatir that yields the largest |
|||
integer that is at most its operand. |
|||
COMMENT |
|||
INT v := ENTIER sqrt( s ); |
|||
COMMENT the construct: WHILE...DO...OD repeatedly executes the |
|||
instructions between DO and OD, the execution stops when |
|||
the instructions between WHILE and DO yield the value FALSE. |
|||
COMMENT |
|||
WHILE ( v * v ) MOD 1 000 000 /= s DO v := v + 1 OD; |
|||
COMMENT print displays the values of its parameters |
|||
COMMENT |
|||
print( ( v, " when squared is: ", v * v, newline ) )</lang> |
|||
{{out}} |
|||
<pre> |
|||
+25264 when squared is: +638269696 |
|||
</pre> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |