home *** CD-ROM | disk | FTP | other *** search
- \ Problem 5.3 Dan Dubrick Set 14D4
-
- \ Brute force approach to fractions.
- \ Display decimal equivilant of fraction m/n
- : .XXX ( m n -- )
- 2DUP > ABORT" Improper fraction." \ require m < n
- >R 2000 R> */ 1+ 2/ ( Scale and round fraction )
- ASCII . EMIT DUP 10 <
- IF ASCII 0 DUP EMIT EMIT
- ELSE DUP 100 <
- IF ASCII 0 EMIT
- THEN
- THEN . ;
-
- \ Print the decimal equivallent if mixed fraction i+m/n
- : I.XXX ( i m n -- )
- ROT 5 .R .XXX ;
-
- \ Display decimal equivalents of 1/n through n-1/n
- : TEST ( n -- )
- CR DUP 1
- ?DO CR I OVER 2DUP SWAP
- . ." /" . ." = " .XXX
- LOOP DROP ;
-
- \ Calculate the area of a circle and display to three decimal places.
- : SPHERE_AREA ( r -- )
- DUP 4 * * 355 113 \ The ratio for pi
- */MOD SWAP 113 \ Remainder for I.XXX
- ." The area of the sphere is " I.XXX ;
-
- \ Calculate the volume of a cone and display to three decimal places.
- : CONE_VOLUME ( h r -- )
- DUP * * 3 / 355 113 \ The ratio for pi
- */MOD SWAP 113 \ Remainder for I.XXX
- ." The area of the sphere is " I.XXX ;
-
-
-