/*******************************************************************************************
04-A.CPP
    answer to problem A, Practical #4
*******************************************************************************************/

#include <iostream.h>


void GetResults(double list[], const int size);
void DisplayResults(double list[], const int size);
double factoral(const int n);


void main()
    {
    const int maxsize = 20;
    double Factorals[maxsize];

    cout << "This program displays the factoral (!n)\n"
         << "of the numbers from 1 to 20" << endl << endl;

    GetResults(Factorals, maxsize);
    DisplayResults(Factorals, maxsize);
    }


void GetResults(double list[], const int size)
    {
    for (int i = 0; i < size; i++)
        {
        list[i] = factoral(i+1);
    }
    }

void DisplayResults(double list[], const int size)
    {
    cout << " n" << "\t    !n" << endl
         << "---" << "\t-----------" << endl;
    for (int i = 0; i < size; i++)
        {
        cout << i << '\t' << list[i] << endl;
    }
    }

double factoral(const int n)
    {
    double result = 1;
    for (int i = n; i > 1; i--)
        result = result * i;

    return result;
    }