diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-13 17:42:52 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-13 17:42:52 +0100 |
| commit | a1a5447b8b040b100bad89766066ae4ba8d6d920 (patch) | |
| tree | f255a6da6b6af8daa1906bd834131052b64a2ca5 /semestre 2/informatique/tme/semaine3/17_compter_random.c | |
| parent | 755d27882e2cb21a5e30b6854bea8e4454f2328d (diff) | |
Ajout de la semaine des cours du 7 au 13 février
Diffstat (limited to 'semestre 2/informatique/tme/semaine3/17_compter_random.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine3/17_compter_random.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine3/17_compter_random.c b/semestre 2/informatique/tme/semaine3/17_compter_random.c new file mode 100644 index 0000000..10a1ff3 --- /dev/null +++ b/semestre 2/informatique/tme/semaine3/17_compter_random.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define NB_VALEURS 20 +#define VMIN -20 +#define VMAX 20 + +int valeur_aleatoire(int min, int max){ + return min + rand()%(max+1-min); +} + +void pos_neg_zero(int *neg, int *zero, int *pos, int v){ + if (v > 0) (*pos)++; + else if (v < 0) (*neg)++; + else (*zero)++; +} + +int main(){ + srand(time(NULL)); + int neg = 0, pos = 0, zero = 0; + for (int i = 0; i < NB_VALEURS; i++){ + int v = valeur_aleatoire(VMIN, VMAX); + pos_neg_zero(&neg, &zero, &pos, v); + } + printf("valeurs:\n\t- positives: %d\n\t- nulles: %d\n\t- négatives: %d\n", pos, zero, neg); + return 0; +} + |
