TP2
This commit is contained in:
52
TP2/2.3.cpp
Normal file
52
TP2/2.3.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int Nmax = 100;
|
||||
|
||||
void Saisie(int tab[], int &n, int &S, float &Moy);
|
||||
void Affichage(int tab[], int n, int S, float Moy);
|
||||
|
||||
void main()
|
||||
{
|
||||
int N, S;
|
||||
float Moy;
|
||||
int Tab[Nmax];
|
||||
|
||||
Saisie(Tab, N, S, Moy);
|
||||
Affichage(Tab, N, S, Moy);
|
||||
}
|
||||
|
||||
void Saisie(int tab[], int &n, int &S, float &Moy)
|
||||
{
|
||||
cout << "Entrez la taille du tableau : ";
|
||||
cin >> n;
|
||||
|
||||
if (n > Nmax)
|
||||
{
|
||||
n = Nmax;
|
||||
cout << "La taille maximale du tableau est de " << Nmax;
|
||||
}
|
||||
|
||||
S = 0;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << "tab[" << i << "]" << " = ";
|
||||
cin >> tab[i];
|
||||
S += tab[i];
|
||||
}
|
||||
|
||||
Moy = S / (float)n;
|
||||
}
|
||||
|
||||
void Affichage(int tab[], int n, int S, float Moy)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << "tab[" << i << "]" << " = " << tab[i] << endl;
|
||||
}
|
||||
|
||||
cout << "Somme = " << S << endl;
|
||||
cout << "Moyenne = " << Moy << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user