0% found this document useful (0 votes)
11 views4 pages

Guide des Tableaux et Matrices en Programmation

The document provides instructions for working with arrays and matrices in programming, including declaration, reading, writing, and performing operations such as sum, average, maximum, minimum, and searching for values. It also covers merging arrays, transforming between arrays and matrices, and performing matrix addition and multiplication. Additionally, it includes methods for permuting rows and columns and extracting diagonal elements.

Uploaded by

tebbaladel25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Guide des Tableaux et Matrices en Programmation

The document provides instructions for working with arrays and matrices in programming, including declaration, reading, writing, and performing operations such as sum, average, maximum, minimum, and searching for values. It also covers merging arrays, transforming between arrays and matrices, and performing matrix addition and multiplication. Additionally, it includes methods for permuting rows and columns and extracting diagonal elements.

Uploaded by

tebbaladel25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Berrabah Anes( @the_actual_lloyd_b)

Les Tableaux (Arrays)


Description Instruction
Declaration Var
N : la taille du tableau T:array [1..N] of integer;
Integer : le type (integer, char, i: integer;
sting,bool,real)
La lecture For i :=1 to n do
En utilisant la boucle pour Read (T[i]) ;
L’écriture For i :=1 to n do
En utilisant la boucle pour Write (T[i]) ;
La somme du tableau S:=0;
For i :=1 to n do
Var S:=S+t[i];
S: integer;
Write(‘la somme de tableau est’, s) ;
La somme conditionnel S:=0;
For i :=1 to n do
If(condition sur S)then
S:=S+t[i];
Write(‘la somme de tableau est’, s) ;
Moyenne (apres la somme) Moy= S/ N ;
Var Write(‘Moyenne de tableau est’, Moy) ;
Moy:real;

Maximum Max:=t[1];
Var For i :=1 to n do
Max :integer ; If(t[i]>Max)then
Max:=t[i];
Write(‘Maximum de tableau est’, Max) ;
Minimum Min:=t[1];
Var For i :=1 to n do
Min :integer ; If(t[i]<Min)then
Min:=t[i];
Write(‘Mininmum de tableau est’, Min) ;
Recherche Cpt:=0;
Val,Cpt : integer ; Read(Val);
For i :=1 to n do
If(t[i]=Val)then
Cpt:=Cpt+1;
If (Cpt =0) then
Write(Val , ‘exist pas dans Tableau’)
else
Write(Val , ‘exist dans Tableau’ , Cpt,
‘fois’) ;
Berrabah Anes( @the_actual_lloyd_b)

Fusionner deux tableaux K:=1;


Var For i:=1 to N do
T2:array [1..N] of integer; Begin
T3:array [1..M] of integer; T3[k]:=T[i]
K:integer; K:=k+1;
End;
For i:=1 to N do
Begin
T3[k]:=T[i];
K:=k+1;
End;

Les Matrices(Arrays)
Description Instruction
Declaration Var
N : nombre de lignes Mat:array [1..N,1..M] of integer;
M : nombre de colones i,j: integer;

Integer : le type (integer, char,


sting,bool,real)
La lecture Read(N,M)
En utilisant deux boucle pour For i :=1 to N do
For j :=1 to M do
Read (Mat[i,j]) ;

L’écriture For i :=1 to N do


En utilisant deux boucle pour begin
Writeln(‘ ’);
For j :=1 to M do
write(Mat[i,j],’ ‘) ;
end;
La somme du Matrice S:=0;
For i :=1 to N do
Var For j :=1 to M do
S: integer; S:=S+ Mat[i,j];

Write(‘la somme de Matrice est’, s) ;


Moyenne (apres la somme) Moy= S/ N ;
Var Write(‘Moyenne de Matrice est’, Moy) ;
Moy:real;

Maximum Max:= Mat[1,1];


Var For i :=1 to N do
Berrabah Anes( @the_actual_lloyd_b)
Max :integer ; For j :=1 to M do
If(Mat[i,j]>Max)then
Max:= Mat[i,j] ;
Write(‘Maximum de matrice est’, Max) ;
Minimum Max:= Mat[1,1];
Var For i :=1 to N do
Min :integer ; For j :=1 to M do
If(Mat[i,j]<Min)then
Max:= Mat[i,j] ;
Write(‘Minimum de matrice est’, Min) ;
Recherche
Val,Cpt : integer ; Cpt:=0;
Read(Val);
For i :=1 to N do
For j :=1 to M do
If( Mat[i,j] =Val)then
Cpt:=Cpt+1;
If (Cpt =0) then
Write(Val , ‘exist pas’)
else
Write(Val , ‘exist dans’ , Cpt, ‘fois’) ;

Transformation de matrice a un tableau K :1 ;


Var For i :=1 to N do
T:array [1..1000] of integer; For j :=1 to M do
k:integer ; Begin
T[k]:=Mat[i,j];
K:=k+1
End;

Transformation de tableau a une matrice K :1 ;


Var For i :=1 to N do
T:array [1..1000] of integer; For j :=1 to M do
k:integer ; Begin
Mat[i,j]:= T[k];
K:=k+1
End;

Somme de deux matrices For i :=1 to N do


var For j :=1 to M do
Mat2,Mat3 :array [1..N,1..M] of integer; Mat3[i,j]:= Mat2[i,j]+ Mat[i,j];
Berrabah Anes( @the_actual_lloyd_b)
Produit de deux matrice for i:=1 to N do
Mat2,Mat3 :array [1..N,1..N] of integer; for j:=1 to N do
K:integer; begin
mat3[i,j]:=0;
for k:=1 to N do
Mat3[i,j]:=Mat3[i,j]+Mat[i,k]*Mat2[k,j];
end;
end;
Permutation de deux colones Read(c1,c2);
Val for i:=1 to N do
C1, C2,X : integer ; begin
X:=Mat[i,c1];
Mat[i,c1]:=Mat[i,c2];
Mat[i,c2]:=X;
End;
Permutation de deux lignes Read(L1,L2);
Val for i:=1 to M do
L1 ,L2,X : integer ; begin
X:=Mat[L1,i];
Mat[L1,i]:=Mat[L2,i];
Mat[L2,i]:=X;
End;
Diagonal For i :=1 to N do
For j :=1 to M do
If(i = j) then
write(Mat[i,j],’ ‘) ;

Common questions

Powered by AI

To transform an array back into a matrix, declare the matrix and set indices for transformation. Use a pair of nested for loops that iterate over the matrix's rows and columns. Assign values from the one-dimensional array to corresponding positions in the matrix array by maintaining an index that progresses through the array as elements are copied into the matrix structure . It is crucial to keep track of indices to ensure that each element is appropriately placed in the matrix, maintaining matrix structure integrity.

To swap two columns in a matrix, read the indices of the two columns to swap. Use a loop to go through each row of the matrix, swapping elements at the specified column indices. Use a temporary variable to facilitate the swap—assign one value to the temporary variable, replace it with the other value, and then copy the temporary variable's value to the other position . This ensures data integrity during the swap.

To calculate the sum of values within an array, initialize a sum variable to 0. Use a for loop to iterate through each element of the array, accumulating each element's value into the sum variable. Finally, output the sum . For a conditional sum, within the loop, check a specified condition before adding each element's value to the sum. If the condition is met, include the value in the sum; otherwise, do not .

To find the maximum value in a matrix, initialize a variable to store the maximum with the first element of the matrix. Use two nested for loops to iterate through each element of the matrix. Within the inner loop, compare each element with the current maximum. If an element is larger, update the maximum variable with its value. After completing the iterations, the maximum variable holds the largest value in the matrix .

To merge two arrays, first, iterate over the elements of the first array using a for loop, and copy each element to a new array. Then similarly iterate over the elements of the second array, continuing to add elements to the new array from where the first left off. This involves maintaining an index or counter to track the insertion point in the new array during both loops .

First, calculate the sum of the array's elements. Then divide this sum by the number of elements in the array to compute the average. The result represents the average value of all elements in the array . Consider the size of the array to avoid division by zero errors by ensuring the array has elements .

To transform a matrix into a one-dimensional array, declare the necessary array. Then, use two nested for loops to traverse the matrix by rows and columns. Assign each element of the matrix to the array in a sequential manner by incrementing the index in the array for each element copied from the matrix . This process requires careful handling of indices to ensure correct mapping from two-dimensional to one-dimensional storage .

Matrix multiplication involves using three nested loops—iterate the rows of the first matrix, columns of the second matrix, and across the shared dimension (columns of the first and rows of the second). For each pair of row and column, calculate the dot product by summing products of corresponding elements. Accumulate this sum into the resulting matrix's element position. This requires careful index tracking and initialization of the resulting matrix to zero to ensure accurate computation .

Initialize a variable with the value of the first element of the matrix to store the minimum. Employ two nested loops to iterate over each element—rows and columns of the matrix. Within the innermost loop, compare each element with the current minimum value. If any element is smaller, update the minimum variable with this new value . Upon completion, the minimum variable will contain the smallest value found within the matrix.

The methodology involves initializing a counter to zero and reading the target value. Use a for loop to iterate through each element of the array, checking if each element matches the target. If a match is found, increment the counter. After the loop, check the counter. If zero, the value doesn't exist; otherwise, it reports how many times it appeared . This method effectively handles both the search and the reporting of results .

You might also like