// 01312008.cpp, P H Anderson, Jan 31, '08

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

FILE *fw;

int main(void)
{
    int n, v, coin_flip, counter;
    float f, percent, x, y;
   
    for (n=0; n<25; n++) // display some random numbers in range 0 - 99
    {
        v = rand()%100;
        printf("%d ", v);
    }    
    
    while(getchar() != 'x') // pause to admire
    {
    }
    
    for (n=0; n<25; n++) // display some random floats in range 0.0 - 1.0
    {
        f = (float) (rand()%100) / 100.0;
        printf("%f\n", f);
    }   
    
    while(getchar() != 'x') // pause to admire
    {
    }
   
    counter = 0; // flip a coin 10,000 times
    for (n=0; n<10000; n++)
    {
        coin_flip = rand() % 2;
        if (coin_flip == 0)
        {
            ++counter;
        }    
    }
    
    percent = 100 * (float) counter / 10000;
    printf("%d %.2f\n", counter, percent);
   
    
    while(getchar() != 'x') // pause to admire
    {
    }
    
    fw = fopen("c:\\test.dta", "wt");
    
    for (n=0; n<=20; n++)
    {
        x = 0.0 + 2.0 * M_PI * n/20;  // over the range of 0 to 2 PI
        y = 10.0 * sin(x);
        printf("%15.4f\t%15.4f\n", x, y);
        fprintf(fw, "%15.4f,%15.4f\n", x, y);
    }
        
    fclose(fw);    
        
    while(getchar() != 'x') // pause to admire
    {
    }    
    
}