First commit
This commit is contained in:
85
IUT/Info1/TD/Exercices/10.6/10.6.md
Normal file
85
IUT/Info1/TD/Exercices/10.6/10.6.md
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
{
|
||||
R : Permute 2 lignes passées en paramètre dans un tableau
|
||||
E : index_ligne1 et index_ligne2 les entiers correspondants au lignes, nb_lignes : un entier nb_colonnes un entiers,
|
||||
E/S : tab un tableau de tableaux
|
||||
S : Vide
|
||||
}
|
||||
permutation_lignes : une fonction (tab: un tableau de tableaux de 6 entiers, index_ligne1 : un entier, index_ligne2 : un entier, nb_lignes : un entier, nb_colonnes : un entier) -> Vide
|
||||
Lexique :
|
||||
i : un entier
|
||||
temporaire : un entier
|
||||
Algorithme :
|
||||
Début
|
||||
Si (index_ligne1 < nb_lignes) ET (index_ligne1 >= 0) ET (index_ligne2 < nb_lignes) ET (index_ligne2 >= 0)
|
||||
Faire
|
||||
i <- 0
|
||||
Tant Que i < nb_colonnes
|
||||
Faire temporaire <- tab[index_ligne1][i]
|
||||
tab[index_ligne1][i] <- tab[index_ligne2][i]
|
||||
tab[index_ligne2][i] <- temporaire
|
||||
i <- i + 1
|
||||
FinTantQue
|
||||
FinSi
|
||||
Fin
|
||||
|
||||
|
||||
{
|
||||
R : Permute 2 colonnes passées en paramètre dans un tableau
|
||||
E : index_col1 et index_col2 les entiers correspondants au colonnes, nb_lignes : un entier nb_colonnes un entiers,
|
||||
E/S : tab un tableau de tableaux
|
||||
S : Vide
|
||||
}
|
||||
permutation_colonnes : une fonction (tab: un tableau de tableaux, index_col1 : un entier, index_col2 : un entier, nb_lignes : un entier, nb_colonnes : un entier) -> Vide
|
||||
Lexique :
|
||||
i : un entier
|
||||
temporaire : un entier
|
||||
Algorithme :
|
||||
Début
|
||||
Si (index_col1 < nb_colonnes) ET (index_col1 >= 0) ET (index_col2 < nb_lignes) ET (index_col2 >= 0)
|
||||
Faire
|
||||
i <- 0
|
||||
Tant Que i < nb_lignes
|
||||
Faire temporaire <- tab[i][index_col1]
|
||||
tab[i][index_col1] <- tab[i][index_col2]
|
||||
tab[i][index_col2] <- temporaire
|
||||
i <- i + 1
|
||||
FinTantQue
|
||||
FinSi
|
||||
Fin
|
||||
|
||||
{
|
||||
R : Affiche un tableau à 2 dimensions
|
||||
E : tab un tableau de tableau de 6 entiers, nb_lignes et nb_colonnes 2 entiers
|
||||
S : Vide
|
||||
On ne sais pas faire varier le nombre de colonnes
|
||||
}
|
||||
afficher_tableau : un fonction(tab : un tableau de tableaux de 6 entiers, nb_lignes : un entier, nb_colonnes : un entier) -> Vide
|
||||
Lexique :
|
||||
i : un entier
|
||||
j : un entier
|
||||
Algorithme :
|
||||
Début
|
||||
Si (nb_lignes > 0) ET (nb_colonnes > 0) ET (nb_colonnes < 6)
|
||||
i <- 0
|
||||
Faire Tant Que i < nb_lignes
|
||||
Faire Ecrire("| ")
|
||||
j <- 0
|
||||
Tant que j < nb_colonnes
|
||||
Faire Ecrire(tab[i][j], " ")
|
||||
FinTantQue
|
||||
Ecrire("|")
|
||||
FinTantQue
|
||||
FinSi
|
||||
Fin
|
||||
|
||||
|
||||
|
||||
|
||||
Lexique :
|
||||
tab : un tableau de 4 tableau de 6 entiers := {
|
||||
{02; 03; 05; 07; 11; 13};
|
||||
{17; 19; 23; 29; 31; 37};
|
||||
{41; 43; 47; 53; 59; 61};
|
||||
{67; 71; 73; 79; 83; 89}
|
||||
}
|
||||
BIN
IUT/Info1/TD/Exercices/10.6/a.exe
Normal file
BIN
IUT/Info1/TD/Exercices/10.6/a.exe
Normal file
Binary file not shown.
26
IUT/Info1/TD/Exercices/10.6/main.cpp
Normal file
26
IUT/Info1/TD/Exercices/10.6/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "tab.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
const unsigned int nb_lignes = 4;
|
||||
const unsigned int nb_colonnes = 6;
|
||||
unsigned int tab[nb_lignes][nb_colonnes] = {
|
||||
{2, 3, 5, 7, 11, 13},
|
||||
{17, 19, 23, 29, 31, 37},
|
||||
{41, 43, 47, 53, 59, 61},
|
||||
{67, 71, 73, 79, 83, 89}
|
||||
};
|
||||
|
||||
afficher_tableau(tab, nb_lignes, nb_colonnes);
|
||||
|
||||
permutation_lignes(tab, 0, 2, nb_lignes, nb_colonnes);
|
||||
|
||||
afficher_tableau(tab, nb_lignes, nb_colonnes);
|
||||
|
||||
permutation_colonnes(tab, 1, 4, nb_lignes, nb_colonnes);
|
||||
|
||||
afficher_tableau(tab, nb_lignes, nb_colonnes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
IUT/Info1/TD/Exercices/10.6/tab.cpp
Normal file
63
IUT/Info1/TD/Exercices/10.6/tab.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "tab.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void permutation_lignes(
|
||||
unsigned int tab[][6],
|
||||
unsigned int index_ligne1,
|
||||
unsigned int index_ligne2,
|
||||
unsigned int nb_lignes,
|
||||
unsigned int nb_colonnes
|
||||
) {
|
||||
unsigned int temp;
|
||||
|
||||
if ((index_ligne1 < nb_lignes) && (index_ligne2 < nb_lignes)) {
|
||||
for (unsigned int i = 0; i < nb_colonnes; i++) {
|
||||
temp = tab[index_ligne1][i];
|
||||
tab[index_ligne1][i] = tab[index_ligne2][i];
|
||||
tab[index_ligne2][i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void permutation_colonnes(
|
||||
unsigned int tab[][6],
|
||||
unsigned int index_colonne1,
|
||||
unsigned int index_colonne2,
|
||||
unsigned int nb_lignes,
|
||||
unsigned int nb_colonnes
|
||||
) {
|
||||
unsigned int temp;
|
||||
|
||||
if ((index_colonne1 < nb_colonnes) && (index_colonne2 < nb_colonnes)) {
|
||||
for (unsigned int i = 0; i < nb_lignes; i++) {
|
||||
temp = tab[i][index_colonne1];
|
||||
tab[i][index_colonne1] = tab[i][index_colonne2];
|
||||
tab[i][index_colonne2] = temp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void afficher_tableau(
|
||||
unsigned int tab[][6],
|
||||
unsigned int nb_lignes,
|
||||
unsigned int nb_colonnes
|
||||
) {
|
||||
if ((nb_lignes == 0) || (nb_colonnes == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < nb_lignes; i++) {
|
||||
cout << "| ";
|
||||
|
||||
for (unsigned int j = 0; j < nb_colonnes; j++) {
|
||||
cout << tab[i][j] << " ";
|
||||
}
|
||||
|
||||
cout << "|" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
5
IUT/Info1/TD/Exercices/10.6/tab.h
Normal file
5
IUT/Info1/TD/Exercices/10.6/tab.h
Normal file
@@ -0,0 +1,5 @@
|
||||
void permutation_lignes(unsigned int tab[][6], unsigned int index_ligne1, unsigned int index_ligne2, unsigned int nb_lignes, unsigned int nb_colonnes);
|
||||
|
||||
void permutation_colonnes(unsigned int tab[][6], unsigned int index_colonne1, unsigned int index_colonne2, unsigned int nb_lignes, unsigned int nb_colonnes);
|
||||
|
||||
void afficher_tableau(unsigned int tab[][6], unsigned int nb_lignes, unsigned int nb_colonnes);
|
||||
Reference in New Issue
Block a user