cpp/tp0/p3/main.cpp
2021-12-18 14:56:50 +01:00

37 lines
867 B
C++
Executable file

#include <iostream>
#define MAX 10
using namespace std;
float calculMoyenne (float dsqdsq[]);
int calculMoyenne (int tab[]);
int main()
{
int tabEntier[MAX+1]={10,12,20,18,9,10,12,20,18,15};
float tabFlottant[MAX+1]={1.0,2.3,5.7,2.1,7.3,2.4,5.6,7.1,5.0,3.0};
int moyenneEntier = calculMoyenne(tabEntier);
float moyenneFlottant = calculMoyenne(tabFlottant);
cout << "Moyenne Entier :" << moyenneEntier << endl;
cout << "Moyenne Flottant :" << moyenneFlottant << endl;
return 0;
}
float calculMoyenne (float tab[])
{
float moyenne(0);
for(int i(0); i<MAX ; i++)
{
moyenne = moyenne + tab[i];
};
return moyenne/10;
}
int calculMoyenne (int tab[])
{
int moyenne(0);
for(int i(0); i<MAX; i++)
{
moyenne = moyenne + tab[i];
}
return moyenne/MAX;
}