TP2
This commit is contained in:
65
TP2/2.4.cpp
Normal file
65
TP2/2.4.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int Nmax = 10;
|
||||
|
||||
void Saisie(int tab[][Nmax], int &n1, int &n2, int &S, float &Moy);
|
||||
void Affichage(int tab[][Nmax], int n1, int n2, int S, float Moy);
|
||||
|
||||
void main()
|
||||
{
|
||||
int N1, N2, S;
|
||||
float Moy;
|
||||
int Tab[Nmax][Nmax];
|
||||
// i*n1 + j
|
||||
Saisie(Tab, N1, N2, S, Moy);
|
||||
Affichage(Tab, N1, N2, S, Moy);
|
||||
}
|
||||
|
||||
void Saisie(int tab[][Nmax], int &n1, int &n2, int &S, float &Moy)
|
||||
{
|
||||
cout << "Entrez le nombre de lignes : ";
|
||||
cin >> n1;
|
||||
cout << "Entrez le nombre de colonnes : ";
|
||||
cin >> n2;
|
||||
|
||||
if (n1 > Nmax)
|
||||
{
|
||||
n1 = Nmax;
|
||||
cout << "La taille maximale du tableau est de " << Nmax;
|
||||
}
|
||||
if (n2 > Nmax)
|
||||
{
|
||||
n2 = Nmax;
|
||||
cout << "La taille maximale du tableau est de " << Nmax;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n1; i++)
|
||||
{
|
||||
for (int j = 0; j < n2; j++)
|
||||
{
|
||||
cout << "tab[" << i << "]" << "[" << j << "]" << " = ";
|
||||
cin >> tab[i][j];
|
||||
S += tab[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
Moy = (float)S / (n1 + n2);
|
||||
}
|
||||
|
||||
void Affichage(int tab[][Nmax], int n1, int n2, int S, float Moy)
|
||||
{
|
||||
for (int i = 0; i < n1; i++)
|
||||
{
|
||||
for (int j = 0; j < n2; j++)
|
||||
{
|
||||
cout << tab[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
// cout << "tab[" << i << "]" << " = " << tab[i] << endl;
|
||||
}
|
||||
|
||||
cout << "Somme = " << S << endl;
|
||||
cout << "Moyenne = " << Moy << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user