diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-03-10 10:31:33 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-03-10 10:31:33 +0100 |
| commit | 4a3afaf44aa29e66a6c879c60322015a2920a5ab (patch) | |
| tree | 64d3e7748078b4215341aeead3b30eaaf28070ad /semestre 2/informatique/tme/semaine5/28_participation_frais.c | |
| parent | 77bfb2ccd3152c1f41d43dc192ba86ca8fd0f72f (diff) | |
Ajout de la semaine des cours du 3 au 7 mars
Diffstat (limited to 'semestre 2/informatique/tme/semaine5/28_participation_frais.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine5/28_participation_frais.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine5/28_participation_frais.c b/semestre 2/informatique/tme/semaine5/28_participation_frais.c new file mode 100644 index 0000000..e5aff0d --- /dev/null +++ b/semestre 2/informatique/tme/semaine5/28_participation_frais.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#define NB_AMIS 4 +#define NB_JOURS 7 + +void init_tab(float tab[NB_AMIS][NB_JOURS]){ + for (int i = 0; i < NB_AMIS; i++) { + for (int j = 0; j < NB_JOURS; j++) tab[i][j] = 0; + } +} + +void random_tab(float tab[NB_AMIS][NB_JOURS], int j) { + int a = rand()%NB_AMIS; + int v = rand()%21+30; + tab[a][j] = v; + for (int i = 0; i < NB_AMIS; i++) { + if (i != a) tab[i][j] = (float) v/(-NB_AMIS+1); + } +} + +void show_tab(float tab[NB_AMIS][NB_JOURS]){ + printf("Jour/Ami||\t"); + for (int i = 0; i < NB_AMIS; i++) printf("%d\t|\t", i+1); + printf("\n"); + for (int i = 0; i < NB_AMIS*18; i++) printf("-"); + printf("\n"); + for (int j = 0; j < NB_JOURS;j++){ + for (int i = 0; i < NB_AMIS; i++) { + if (i == 0) printf("%d\t||\t", j+1); + printf("%.2f\t|\t", tab[i][j]); + if (i == NB_AMIS-1) printf("\n"); + } + } +} + +void show_solde(float tab[NB_AMIS][NB_JOURS], int a){ + float s = 0; + for (int j = 0; j < NB_JOURS; j++) s += tab[a][j]; + printf("Ami %d a pour solde %.02f\n", a, s); +} + +int main() { + float tab[NB_AMIS][NB_JOURS] = {}; + srand(time(NULL)); + init_tab(tab); + for (int d = 0; d < NB_JOURS; d++) random_tab(tab, d); + show_tab(tab); + for (int i = 0; i < NB_AMIS; i++) show_solde(tab, i); + return 0; +} + |
