[go: up one dir, main page]

0% found this document useful (0 votes)
22 views2 pages

Correction Lab#08

The document contains algorithms written in pseudocode to perform operations on matrices such as summing two matrices, finding the maximum value and its indices in a matrix, counting even and odd elements in a matrix rows and columns, calculating the product of elements in each row of a matrix, and finding the row with the maximum product. It also contains a C program to input a matrix from the user, calculate the sum and average of elements, and count elements greater than the average.
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)
22 views2 pages

Correction Lab#08

The document contains algorithms written in pseudocode to perform operations on matrices such as summing two matrices, finding the maximum value and its indices in a matrix, counting even and odd elements in a matrix rows and columns, calculating the product of elements in each row of a matrix, and finding the row with the maximum product. It also contains a C program to input a matrix from the user, calculate the sum and average of elements, and count elements greater than the average.
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
You are on page 1/ 2

UNIVERSITY OF CONSTANTINE 1– CAMPUS CHAAB ERSAS1 ST YEAR COMMON CORE - ST

Computer Science II - Correction of Exercise Series No. 08 : Matrices.

Part I : Algorithms
Exercise No. 01 Exercise No. 03
Algorithm Sum2Mat; Algorithm SEV_COV;
Constants n=10; m=15; Constants n=4; m=8;
Variables Variables
A,B,S: matrix[1..n,1..m] of integer; Mat: matrix[1..n,1..m]of integer;
i, j : integer; i,j,S,Co : integer;
Begin
For i=1 to n Do Begin
For j=1 to m Do For i=1 to n Do
Read (A[i,j]); For j=1 to m Do
EndFor Read (Mat[i,j]);
EndFor EndFor
For i=1 to n Do EndFor
For j=1 to m Do
Read (B[i,j]); For i=1 to n Do
EndFor S0;
EndFor For j=1 to m Do
For i=1 to n Do If (Mat[i,j]mod2 = 0) Then
For j=1 to m Do S  S + Mat[i,j];
S[i,j] A[i,j]+B[i,j]; EndIf
EndFor EndFor
EndFor Write('Row:',i,'Sum:',S);
EndFor
For i=1 to n Do
For j=1 to m Do
For j=1 to m Do
Write (S[i,j]);
EndFor Co  0;
EndFor For i=1 to n Do
End. If (Mat[i,j]mod2 <> 0) Then
Co  Co + 1;
Exercise No. 02 EndIf
Algorithm MaxIndices; EndFor
Constants n=5; m=5; Write('Column:',j,'Count:',Co);
Variables EndFor
Mat: matrix[1..n,1..m]d’integer; End.
i,j, Max,iMax,jMax: integer;
Begin
For i=1 to n Do
For j=1 to m Do
Read (Mat[i,j]);
EndFor
EndFor
Max  Mat[1,1];
iMax  1; jMax  1;
For i=1 to n Do
For j=1 to m Do
If (Mat[i,j]>Max) Then
Max  Mat[i,j];
iMax  i; jMax  j;
EndIf
EndFor
EndFor
Write ('Maximum value =', Max);
Write ('Indices =',iMax, jMax);
End.
UNIVERSITY OF CONSTANTINE 1– CAMPUS CHAAB ERSAS1 ST YEAR COMMON CORE - ST
Computer Science II - Correction of Exercise Series No. 08: Matrices.

Exercise No. 04 Part II : Programming in C

Algorithm Calculate; #include <stdio.h>


Constants n=20; #define N 3
Variables #define M 4
X: matrix[1..n,1..n]of real; main()
i,j,row : integer; {
Max,prod : real; typedef int A_Type[N][M];
Begin A_Type A;
For i=1 to n Do int i, j, sum, co; float avr;
For j=1 to n Do
printf("Enter the elements of
Read (X[i,j]);
EndFor the matrix : \n");
EndFor for (i=0; i<N ; i++)
for (j=0; j<M ; j++)
scanf("%i", &A[i][j]);
Prod  1;
For j=1 to n Do sum = 0;
Prod  Prod * X[1,j]; for (i=0; i<N ; i++)
EndFor for (j=0; j<M ; j++)
sum = sum+ A[i][j];
row  1; avr = (float)sum/(N*M);
Max  Prod;
co = 0;
For i=2 to n Do for (i=0; i<N ; i++)
Prod  1; for (j=0; j<M ; j++)
For j=1 to n Do if (A[i][j] > avr)
Prod  Prod * X[i,j];
co++;
EndFor
printf("The number of elements
If (Prod > Max) Then greater than %f is: %i", avr, co);
row  i; }
Max  Prod;
EndIf
EndFor

Write('The row number with the


maximum product is : ', row);
End.

You might also like