home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-13 | 2.6 KB | 103 lines | [TEXT/AxoC] |
- LocalLanguage C
- /* -------------------------------------------------
- The following functions demonstrate various aspects of
- AxoCalculator's C programming language.
-
- • To load all functions, choose "Select All"
- under the "Edit" menu, then press "enter".
-
- • To run a function, type its name followed
- by any parameters, then press "enter".
-
- • After the functions are loaded, this file does
- not need to remain open in order to use them.
-
- • Here are some examples of how to use the functions.
-
- BoxVolume (10,15,20)
- Factorial (10)
- RecursiveFact (10)
- SameBirthDateProb (25)
-
- --------------------------------------------------*/
-
-
- /* ---------------- RectArea -------------------
- This function calculates the area of a rectangle
- given its height and width.
- -------------------------------------------------*/
- float RectArea (height, width)
- {
- return (height * width)
- }
-
- /* ---------------- BoxVolume ----------------------
- This function calculates the volume of a box
- given its height, width and depth. It calls the
- function RectArea to get the area of the bottom of
- the box, then multiplies the result by the box depth.
- -------------------------------------------------*/
- float BoxVolume (height, width, depth)
- {
- return RectArea (height, width) * depth
- }
-
- /* ---------------- Factorial -------------------
- This function calculates the factorial of a number.
- -----------------------------------------------*/
- float Factorial (number)
- {
- float f
- int i
-
- f = 1
- for (i = 1 ; i <= Number ; i++) f = f * i
- return f
- }
-
-
- /* ---------------- Factorial -------------------
- This function also calculates the factorial of a number,
- but it uses a recursive algorithm. This approach is
- inefficient, but demonstrates recursion.
- -----------------------------------------------*/
- float RecursiveFact (number)
- {
- if number > 1
- return number * RecursiveFact (number - 1)
- else
- return 1
- }
-
- /* ---------------- SameBirthDateProb -------------------
- This function calculates the probability that two or more
- people in a group have the same birth date, given the
- number of people in the group. It works by calculating
- 1 - the probability that everyone in the group has a
- different birth date.
- -----------------------------------------------*/
- float SameBirthDateProb (numberOfPeople)
- {
- float DiffBirthDateProb
- int i
-
- if (numberOfPeople < 2) then
- DiffBirthDateProb = 1
- else
- {
- if (numberOfPeople > 365) then
- DiffBirthDateProb = 0
- else
- {
- DiffBirthDateProb = 1
- for (i = 2 ; i <= numberOfPeople ; i++)
- {
- DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
- }
- }
- }
- return (1 - DiffBirthDateProb)
- }
-
-
-