// 02122008.cpp, P H Anderson, Feb 12, '07

#include <stdio.h>

// function prototypes
float calc_area_trap(float top, float bottom, float height);

int min_2(int a, int b);
int min_3(int a, int b, int c);
int min_4(int a, int b, int c, int d);

int main(void)
{
    float t, b, h, A;

    int mn;

    A = calc_area_trap(10.0, 4.0, 5.0); // note that values are passed
    printf("Point 1, A= %.2f\n", A);

    t = 10.0; b = 4.0; h = 5.0;
    A = calc_area_trap(t, b, h); // note that values are passed as variables
    printf("Point 2, A= %.2f\n", A);

    printf("Enter t, b and h: ");
    scanf("%f %f %f", &t, &b, &h);
    A = calc_area_trap(t, b, h); // note that values are passed as variables
    printf("Point 3, A= %.2f\n", A);

    mn = min_4(67, 89, -5, 3);
    printf("The minimum is %i\n", mn);

    while(getchar() != 'x')
    {
    }
}

// this is the implementation of the function
float calc_area_trap(float top, float bottom, float height)
{
    float area;
    area = 0.5 * (top + bottom) * height;
    return(area);
}

int min_2(int a, int b)
{
    if (a<b)
    {
        return(a);
    }
    else
    {
        return(b);
    }
}

int min_3(int a, int b, int c)
{
    if (a<min_2(b, c))
    {
        return(a);
    }
    else
    {
        return(min_2(b, c));
    }
}

int min_4(int a, int b, int c, int d)
{
    if (a<min_3(b, c, d))
    {
        return(a);
    }
    else
    {
        return(min_3(b, c, d));
    }
}