Exemple #1
0
int main (int argc, char **argv)
{
    char    line[] = " +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-->";
    char    numbers[] = " 0     5     10     15     20     25     30     35     40     45     50";
 
    int boxcount = 8;
    int ballcount = 210;
    int galton_arr[boxcount];
    int i, j;
 
    printf("%s\n%s\n", numbers, line);
 
    galton(boxcount, ballcount, galton_arr);
 
    /* print out the results */
    for (i = 0; i < boxcount; i++) {
        printf("%d |", i);
        for (j = 0; j < galton_arr[i]; j++) {
            /* the '#' indicates the balls */
            printf("#");
        }
        printf(" %d\n%s\n", galton_arr[i], line);
    }
 
    return 0;
}
Exemple #2
0
int main(int argc, const char* argv[])
{
	if (argc > 3)
	{
		// get input: depth of tree, number of rounds, left probability of an element
		int n = atoi(argv[1]);
		int j = atoi(argv[2]);
		float k = atof(argv[3]);

		int* result = galton(n, j, k); // simulate galton

		if (result == NULL)
			printf("You suck.\n"); // wrong input
		else
		{
			for (int i = 0; i < n + 1; i++) // output the result
				printf("We have %d cakes in box #%d\n", result[i], i + 1);

			free(result);
		}
	}

	return 0;
}