All pastes #488929 Raw Edit

Untitled

public c v1 · immutable
·published 2007-05-15 07:49 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>intmain(void) {	const int purchase_max = 15;	const int r = 10;	/* producers */	const int m = 100;	/* consumers */	int i, j;	int a[r];		/* delta were sold per day */	int b[r];		/* remain product to day.begin */	int c[r];		/* remain product to day.end */	int R[r];		/* delta need to buy */	int l[r];		/* remaining min when need to buy */	const int G = 30;	/* period */	int s = 0;		/* day of period */	int A = 0;		/* cumul. total request to this day */	int H = 0;		/* cumul. total neg. response to this day */	srandomdev();	for (i = 0; i < r; ++i) {		b[i] = purchase_max * m;		R[i] = b[i] * 1 / 2;		l[i] = b[i] * 1 / 3;	}			while (s++ < G)		for (i = 0; i < r; ++i) {			a[i] = 0;						for (j = 0; j < m; ++j)				a[i] += random() & purchase_max;			A += a[i];			c[i] = b[i] - a[i];			printf("s=%d i=%d | b=%d, a=%d, c=%d\n", s, i, b[i], a[i], c[i]);			if (c[i] < 0) {				b[i] = R[i];				H += -c[i];			}			else if (c[i] < l[i])				b[i] = c[i] + R[i];			else				b[i] = c[i];		}	printf("H=%d A=%d, H/A=%f\n", H, A, (double)H/A);	return(0);}