4 Centre Universitaire de Naama Exercice 1 :

publicité
Centre Universitaire de Naama
Département des sciences et technologiques
Section : 1ème année ST
Module : Informatique 01
TP N°04 : Les tableaux
Fin
Exercice 1 :
1. Ecrire un algorithme qui déclare et
remplisse un tableau de 7 valeurs
numériques en les mettant toutes à
zéro.
2. Ecrire un algorithme qui déclare et
remplisse un tableau contenant les
six voyelles de l’alphabet latin.
5
6
7
8
9
7
9
1
5
4
6
6
5
2
1
3
4
7
Exercice 7:
Ecrire un algorithme qui affiche la matrice
suivante puis calcule la somme de ces
éléments
4
2
-2
3
10
Ecrire un algorithme qui affiche ce vecteur,
puis l’affiche inversé.
4
8
7
Exercice 3 :
3
Tableau 1 :
Tableau 2 :
Que produit l’algorithme suivant ?
Tableau Nb(5) en Entier
Variable i en Entier
Début
Pour i ← 0 à 5
Nb(i) ← i * i
i suivant
Pour i ← 0 à 5
Ecrire Nb(i)
i suivant
Fin
2
Ecrivez un algorithme constituant un
tableau, à partir de deux tableaux de même
longueur préalablement saisis. Le nouveau
tableau sera la somme des éléments des
deux tableaux de départ.
4
Exercice 2 :
1
Exercice 6:
10
Exercice 4 :
Ecrire un algorithme qui remplit 10 notes
puis calcule la moyenne de ces notes
0
4
2
3
6
7
5
-8
4
6
1
5
-9
11
20
Exercice 8:
Ecrire un programme pascal qui calcule la
somme des éléments de diagonal
4
2
-2
3
10
0
4
2
3
6
7
5
-8
4
6
Que produit l’algorithme suivant ?
Tableau N(6) en Entier
Variables i, k en Entier
Début
N(0) ← 1
Pour k ← 1 à 6
N(k) ← N(k-1) + 2
k Suivant
Pour i ← 0 à 6
Ecrire N(i)
i suivant
1
5
-9
11
20
7
-7
0
5
6
Module : Informatique 1
Chargé par : Mr. BRAHIMI M
10 12 8
15 16 5
20 9
19 11
Exercice 5 :
Page 8
Centre Universitaire de Naama
Département des sciences et technologiques
Section : 1ème année ST
Module : Informatique 01
TP N°04 : Les tableaux
Exercice 1 :
Program table1 ;
Var
A :array[1..7] of integer ;
I :integer ;
Begin
For i :=1 to 7 do
A[i] :=0 ;
Writeln(a[i]) ;
Readln ;
End.
Program table1 ;
Var
b :array[1..6] of string ;
I :integer ;
Begin
B[1] :=’a’ ; B[2] :=’e’ ;B[3] :=’i’ ;
B[4] :=’o’ ;B[5] :=’u’ ;B[6] :=’y’ ;
For i :=1 to 7 do
Writeln(‘le vecteur b’,b[i]) ;
Readln ;
End.
Exercice 2 :
Que produit l’algorithme suivant ?
Tableau Nb(5) en Entier
Variable i en Entier
Début
Pour i ← 0 à 5
Nb(i) ← i * i
i suivant
Pour i ← 0 à 5
Ecrire Nb(i)
i suivant
Fin
Cet algorithme remplit un tableau avec
six valeurs : 0, 1, 4, 9, 16, 25.
Exercice 3 :
1
2
3
4
5
6
7
8
9
10
Program table3 ;
Var
D :array[1..10] of integer ;
I :integer ;
Begin
For i :=1 to 10 do
Readln(d[i]) ;
For i :=10 downto 1 do
Writeln(‘le vecteur inversé est’,d[i]) ;
Readln ;
End.
Exercice 4 :
10 12 8
15 16 5
20 9
19 11
Program table4 ;
Var
note :array[1..10] of integer ;
I,som :integer ;
Begin
For i :=1 to 10 do
Readln(note[i]) ;
For i :=1 to 10 do
Som :=som+note[i] ;
Writeln(‘la moyenne des notes est’,s/10) ;
Readln ;
End.
Exercice 5 :
Que produit l’algorithme suivant ?
Tableau N(6) en Entier
Variables i, k en Entier
Début
N(0) ← 1
Pour k ← 1 à 6
N(k) ← N(k-1) + 2
k Suivant
Pour i ← 0 à 6
Ecrire N(i)
i suivant
Fin
Cet algorithme remplit un tableau avec
les sept valeurs : 1, 3, 5, 7, 9, 11, 13.
Exercice 6:
Module : Informatique 1
Chargé par : Mr. BRAHIMI M
Page 8
Tableau 1 :
4
8
7
9
1
5
4
6
Tableau 2 :
7
6
5
2
1
3
4
7
Program table6 ;
Var
T1 :array[1..8] of integer ;
T2 :array[1..8] of integer ;
T3 :array[1..8] of integer ;
I,som :integer ;
Begin
For i :=1 to 8 do
Readln(t1[i]) ;
Readln(t2[i]) ;
For i :=1 to 8 do
T3[i] := t1[i]+ t2[i] ;
Writeln(‘la somme de deux vecteurs
est:’,t3[i]) ;
Readln ;
End.
0
4
2
3
6
7
5
-8
4
6
1
5
-9
11
20
7
-7
0
5
6
Program table8 ;
Var
m :array[1..5,1..5] of integer ;
Begin
Som :=0 ;
For i :=1 to 5 do
For j :=1 to 5 do
Readln(m[i,j]) ;
For i :=1 to 5 do
For j :=1 to 5 do
Som :=som+ m[i,i] ;
Writeln(‘la somme des éléments de la
diagonale est:’,som) ;
Readln ;
End.
Exercice 7:
4
2
-2
3
10
0
4
2
3
6
7
5
-8
4
6
1
5
-9
11
20
Program table7 ;
Var
m :array[1..5,1..4] of integer ;
Begin
Som :=0 ;
For i :=1 to 5 do
For j :=1 to 4 do
Readln(m[i,j]) ;
For i :=1 to 5 do
For j :=1 to 4 do
Som :=som+ m[i,j] ;
Writeln(‘la somme des éléments de notre
matrice est:’,som) ;
Readln ;
End.
Exercice 8:
4
2
-2
Module : Informatique 1
3
10
Chargé par : Mr. BRAHIMI M
Page 9
Téléchargement