aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c
blob: 26b763e44ef6bb93d2536f23a0f8846d7372520a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <assert.h>
#include <stdio.h>

int jours(int infected, int pop, float percentage){
	int n = 1, c = 0;
	while (n / (float) pop < percentage/100){
		n += infected * n;
		c++;
	}
	return c;
}

float pourcentage(int infected, int pop, int day){
	int n = 1, c = 0;
	while (c < day && n <= pop){
		n += infected*n;
		c++;
	}
	if (n >= pop) return 100;
	return 100*n/ (float) pop;
}

int eps_pres(float a, float b, float eps){
	float v = a - b;
	if (v < 0) v = -v;
	return v < eps;
}

int main(){
	assert(jours(5, 10000, 100) == 6);
	assert(jours(5, 10000, 50) == 5);
	assert(jours(5, 10000, 25) == 5);
	assert(jours(5, 10000, 10) == 4);
	
	assert(eps_pres(pourcentage(5, 10000, 2), 0.36, 0.001));
	assert(eps_pres(pourcentage(5, 10000, 3), 2.16, 0.001));
	assert(eps_pres(pourcentage(5, 10000, 4), 12.96, 0.001));
	assert(eps_pres(pourcentage(5, 10000, 5), 77.76, 0.001));
	assert(eps_pres(pourcentage(5, 10000, 6), 100.00, 0.001));
	return 0;
}