From c49b969659d8761442a560f8feda436bfb7b01e8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 27 Mar 2025 17:24:15 +0100 Subject: Ajout des cours du 10 au 27 mars --- semestre 2/informatique/tme/semaine7/hello.c | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 semestre 2/informatique/tme/semaine7/hello.c (limited to 'semestre 2/informatique/tme/semaine7/hello.c') diff --git a/semestre 2/informatique/tme/semaine7/hello.c b/semestre 2/informatique/tme/semaine7/hello.c new file mode 100644 index 0000000..4e2d9dc --- /dev/null +++ b/semestre 2/informatique/tme/semaine7/hello.c @@ -0,0 +1,41 @@ +#include +#define NB_PLANETES 8 + +/* ici la definition du type planete */ +typedef struct{ + char nom[10]; + float densite; + float distance; + int nbsat; +} planete; + +void affichePlanete(planete p){ + printf("%s : densite = %.2f, distance soleil = %.1f, nb satellites = %d", + p.nom, p.densite, p.distance, p.nbsat); +} + +void afficheToutesPlanetes(planete ps[], int n){ + for (int i = 0; i < n; i++) affichePlanete(*(ps+i)); +} + +void modifieDensite (planete *p, float v) { + p->densite = v; +} + +int main(){ + planete systemeSolaire[NB_PLANETES] ={{"Mercure", 5.42, 58, 0}, {"Venus", 5.25, 108.2, 0}, + {"Terre", 5.52, 149.6,1}, {"Mars", 3.94, 227.9, 2}, {"Jupiter", 1.314, 778.3, 16}, + {"Saturne", 0.69, 1427, 17}, {"Uranus", 1.19, 2869, 15}, {"Neptune", 1.6, 4496, 2}}; + int i; + float d; + + afficheToutesPlanetes(systemeSolaire, NB_PLANETES); + printf("\n"); + scanf("%d", &i); + scanf("%f", &d); + /* on affecte la densite d a la planete d'indice i du tableau systemeSolaire */ + modifieDensite(systemeSolaire+i, d); + affichePlanete(systemeSolaire[i]); + printf("\n"); + return 0; +} -- cgit v1.2.3