- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatTutorial/B0124.cpp File Reference

`#include "MusimatTutorial.h"`

Go to the source code of this file.

## Functions
| MusimatTutorialSection (B0124)
Integer | factorial (Integer x)
Static Void | para1 ()

## Function Documentation

Integer factorial | ( | Integer | x | ) |

Definition at line 15 of file B0124.cpp.

Referenced by para1().

    00015                              {
    00016         Integer n = 1;
    00017         For (Integer i = x; i > 1; i = i - 1)
    00018                 n = n * i;
    00019         Return(n);
    00020 }

MusimatTutorialSection | ( | B0124 |  | ) |

Definition at line 2 of file B0124.cpp.

References para1().

    00002                               {
    00003 Print("*** B.1.24 Recursion ***");
    00004 /*****************************************************************************
    00005
    00006 B.1.24 Recursion
    00007
    00008 Recursion means referring back to a value we’ve calculated previously. Consider the factorial
    00009 operation where 5! means 5 x 4 x 3 x 2 x 1. We could use a For statement to calculate factorials.
    00010 This function calculates factorials using iteration:
    00011 *****************************************************************************/
    00012         para1(); // Step into this function to continue the tutorial
    00013 }

Static Void para1 | ( |  | ) |

Definition at line 22 of file B0124.cpp.

References factorial().

    00022                     {
    00023 /*****************************************************************************
    00024  The statement
    00025  *****************************************************************************/
    00026
    00027 Print(factorial(5));
    00028
    00029 /*****************************************************************************
    00030  prints 120.
    00031
    00032 We start with n = 1 and i = 5. The For loop takes the previous value of n, multiplies it by the
    00033 current value of i and reassigns the value to n. It then decrements i and performs the operation
    00034 repeatedly so long as i > 1.
    00035
    00036 *****************************************************************************/
    00037 }}