2024-12-10 14:02:31 +01:00
|
|
|
main.c
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "moyenne.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("Usage : %s <entiers...>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int taille = argc - 1;
|
|
|
|
int tableau[taille];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < taille; i++) {
|
|
|
|
tableau[i] = atoi(argv[i + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
float moyenne = calculer_moyenne(tableau, taille);
|
|
|
|
printf("Moyenne : %.2f\n", moyenne);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
moyenne.c
|
|
|
|
|
|
|
|
#include "moyenne.h"
|
|
|
|
|
|
|
|
float calculer_moyenne(int *tableau, int taille) {
|
|
|
|
int somme = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < taille; i++) {
|
|
|
|
somme += tableau[i];
|
|
|
|
}
|
|
|
|
return (float)somme / taille;
|
|
|
|
}
|
|
|
|
|
|
|
|
moyenne.h
|
|
|
|
|
|
|
|
#include "moyenne.h"
|
|
|
|
|
|
|
|
float calculer_moyenne(int *tableau, int taille) {
|
|
|
|
int somme = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < taille; i++) {
|
|
|
|
somme += tableau[i];
|
|
|
|
}
|
|
|
|
return (float)somme / taille;
|
|
|
|
}
|