aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine7/hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestre 2/informatique/tme/semaine7/hello.c')
-rw-r--r--semestre 2/informatique/tme/semaine7/hello.c41
1 files changed, 41 insertions, 0 deletions
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 <stdio.h>
+#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;
+}