Search code examples
basic

What can I do to run this BASIC Program?


I recently dug out an old book of mine, The Hawaiian Computer Mystery, published in 1985. There is a fragment of code in BASIC on page 81,

1 For N = 7 to 77
2 Print N, SQR(N) - INT (SQR [N] )
3 Next N
4 End

I can sort of see what it should do, but I can't get it to run. There's apparently an error in the second line, but I can't figure out what.


Solution

  • Assuming that you must find the digits after the decimal point of the square root of a number, than the issue is with the square brackets - they must be round. The following code:

    1 For N = 7 to 77
    2 Print N, SQR(N) - INT (SQR (N) )
    3 Next N
    4 End
    

    (blank line in the end) will produce the following result:

    7             .64575124
    8             .8284271
    9             0
    10            .1622777
    11            .31662488
    12            .46410155
    13            .60555124
    14            .7416575
    15            .87298346
    16            0
    17            1.23105526E-1
    18            .2426405
    19            .35889912
    20            .47213602
    21            .5825758
    22            .69041586
    23            .7958317
    24            .89897966
    25            0
    26            .09901953
    27            .19615221
    28            .29150248
    29            .38516474
    30            .47722578
    31            .5677643
    32            .65685415
    33            .7445626
    34            .8309517
    35            .91608
    36            0
    37            .08276272
    38            .16441393
    39            .24499798
    40            .3245554
    41            .40312433
    42            .48074055
    43            .5574384
    44            .63324976
    45            .7082038
    46            .78233004
    47            .8556547
    48            .9282031
    49            0
    50            .07106781
    51            .14142847
    52            .21110249
    53            .28010988
    54            .34846926
    55            .41619825
    56            .483315
    57            .54983425
    58            .6157732
    59            .68114567
    60            .7459669
    61            .8102498
    62            .8740077
    63            .93725395
    64            0
    65            6.2257767E-2
    66            .1240387
    67            .18535233
    68            .24621105
    69            .30662346
    70            .36660004
    71            .42614937
    72            .485281
    73            .5440035
    74            .60232544
    75            .6602545
    76            .71779823
    77            .77496433