diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-01-31 15:39:30 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-01-31 15:39:30 +0100 |
| commit | d7c69934248f3fab4988c0d37c11feba25d653b8 (patch) | |
| tree | 6c396257cb21374e13a26b8f78c05353806220bc /semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c | |
| parent | ed631f52ee7af474625e37c6855c7c55903317fc (diff) | |
Ajout du début du deuxième semestre
Diffstat (limited to 'semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c b/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c new file mode 100644 index 0000000..26b763e --- /dev/null +++ b/semestre 2/informatique/tme/semaine2/11_propagation_epidemie.c @@ -0,0 +1,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; +} |
