|
Task: we have the matrix with dimension 9x9 (KxM). We must input this matrix and find:
1. The sum of elements above the main diagonal which are not equal to 1.
2. The amount of elements above the main diagonal which are equal to 1.
3. The sum of elements under the main diagonal which are not equal to 0.
4. The amount of elements under the main diagonal which are equal to 0.
5. The sum of elements on the main diagonal.
6. The sum of elements on the second diagonal.
7. The amount of coincident elements on the main and second diagonals: a) by rows; b) by columns.
After all steps we output the results.
Mathematical algorithm:
First of all we input the matrix by rows and output it on the screen. Then we do all the tasks (1-7) step by step and output the results.
Flow Chart:
Program:
Program matrix;
uses crt;
Var k,s3,s2,s1,i,j,n,t,t1,t2,t3,t4:integer;
a: array [1..100,1..100] of integer;
b: array [1..100] of integer;
c: array [1..100] of integer;
Begin
t:=0;
s1:=0;
s2:=0;
s3:=0;
Writeln('Input the dimension of matrix');
Read(n);
Writeln('Input the values of matrix');
For i:=1 to n do
For j:=1 to n do read(a[i,j]);
Writeln('Matrix has a look');
For i:=1 to n do begin
writeln;
for j:=1 to n do
write(a[i,j]:4);
end;
Writeln;
For i:=2 to n do
begin
t:=t+1;
For j:=1 to t do
begin
s1:=s1+a[i,j];
end;
end;
Writeln('The sum of elements of matrix below the main diagonal = ', s1);
For i:=1 to n do
begin
j:=i;
b[i]:=a[i,j];
s2:=s2+a[i,j];
end;
t1:=1;
For i:=n downto 1 do
begin
j:=t1;
c[t1]:=a[i,j];
s3:=s3+a[i,j];
t1:=t1+1;
end;
Writeln('The sum of elements of both diagonals of matrix = ', s2+s3);
k:=0;
For i:=1 to n do
For j:=1 to n do
If a[i,j]=0 then
k:=k+1;
writeln('The number of zeros in matrix = ',k);
t2:=0;
t4:=n;
t3:=0;
For i:=1 to n do begin
If b[i]=c[t4] then
t2:=t2+1;
t4:=t4-1;
end;
For i:=1 to n do
If b[i]=c[i] then
t3:=t3+1;
Writeln('The number of pairs looking at rows = ', t2);
Writeln('The number of pairs looking at columns = ', t3);
Readln;
End.
Conclusion: On this laboratory work we create a program which inputs matrix and do tasks mentioned above.
Дата добавления: 2015-09-29; просмотров: 20 | Нарушение авторских прав
<== предыдущая лекция | | | следующая лекция ==> |
Синтезировать по варианту структуру простого магистрального процессора с одним или двумя АЛУ (возможно наличие отдельного адресного АЛУ), выполняющего от 8-и заданных команд. Разработать форматы | | | Мир до и после дня рождения 1 страница |