/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <math.h>
#include <stdio.h>
int main(void){
double notes[28] = {
12.5, 15.0, 18.0, 9.5, 10.0, 11.5, 10.0, 9.0, 7.0, 12.0,
14.0, 13.5, 5.5, 10.0, 15.0, 18.0, 19.0, 12.0, 14.5, 13.0,
20.0, 9.5, 9.5, 10.0, 12.0, 2.0, 11.0, 7.0 };
double min, max, moyenne, ecartype, mediane;
double temp;
int i;
/*Calcul du min*/
min = notes[0];
for(i = 1; i < 28; i++){
if (notes[i] < min){
min = notes[i];
}
}
printf("min : %f \n", min);
/*Calcul du max*/
max = notes[0];
for(i = 1; i < 28; i++){
if (notes[i] > max){
max = notes[i];
}
}
printf("max : %f \n", max);
/*Calcul de la moyenne*/
moyenne = 0;
for(i = 0; i < 28; i++){
moyenne += notes[i];
}
moyenne = moyenne / 28;
printf("moyenne : %f \n", moyenne);
/*Calcul de l'ecartype*/
ecartype = 0;
for(i = 0; i < 28; i++){
ecartype += pow(notes[i] - moyenne, 2);
}
ecartype = sqrt(ecartype / (28 -1));
printf("ecartype : %f \n", ecartype);
/*Calcul de la mediane
// Il faut trier l'ensemble
for(i=0;i<27;i++) {
for(int j=i+1;j<28;j++) {
if ( notes[i] > notes[j] ) {
temp = notes[i];
notes[i] = notes[j];
notes[j] = temp;
}
}
}
*/
/*Tri a bulle non optimisé */
for(int j=28-1;j>0;j--) {
for(i=0;i<j;i++) {
if ( notes[i] > notes[i+1] ) {
temp = notes[i];
notes[i] = notes[i+1];
notes[i+1] = temp;
}
}
}
for (i = 0 ; i < 28 ; i ++)
printf ("%f \t", notes[i]);
printf("\n");
//La médiane est la demi somme des valeurs N/2 et N/2+1
mediane = (notes[(28-1)/2] + notes[28/2])/2;
printf("mediane : %f \n", mediane);
return 0;
}