Aula 08 - Estruturas de dados homogêneas III - Matrizes
53 pág.

Aula 08 - Estruturas de dados homogêneas III - Matrizes


DisciplinaLaboratório de Programação153 materiais2.483 seguidores
Pré-visualização3 páginas
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima ("A media da matriz foi ", media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 
j = 
media = 0
Variáveis locais são 
criadas
22
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 
media = 0
Entra no loop
externa (linhas)
23
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 0
media = 0
Entra no loop
interno (colunas)
24
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 0
media = 3.4
Media recebe o 
primeiro valor
25
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 1
media = 9.0
Incrementa o loop, faz 
o teste e soma próximo 
valor da linha
26
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 2
media = 13.0
Incrementa o loop, faz 
o teste e soma próximo 
valor da linha
27
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 0
j = 3
media = 13.0
Após incremento de 
j, teste falha no 
loop interno
28
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 3
media = 13.0
Incrementa o loop
externo
29
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 0
media = 13.0
Entra novamente no 
loop interno e zera j
30
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 0
media = 15.0
Soma valor da matriz à
variável média
31
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 1
media = 16.1
Incrementa o loop, faz 
o teste e soma próximo 
valor da linha
32
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 2
media = 21.0
Incrementa o loop, faz 
o teste e soma próximo 
valor da linha
33
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 1
j = 3
media = 21.0
Após incremento de 
j, teste falha no 
loop interno
34
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 2
j = 3
media = 21.0
Após incremento de 
i, teste falha no 
loop externo
35
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 2
j = 3
media = 21.0
Retorna o valor da 
média (21.0) divido 
por 6.0
36
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal
{
real mat[2][3] \ufffd\ufffd\ufffd\ufffd {{3.4,5.6,4.0},{2.0,1.1,4.9}};
real media \ufffd\ufffd\ufffd\ufffd mediaMatriz(mat);
imprima (&quot;A media da matriz foi &quot;, media);
}
4.91.12.0
4.05.63.4
Variáveis:
i = 2
j = 3
media = 21.0
Variável local \u201cmédia\u201d
recebe valor da retornado 
pela função
37
Teste de mesa
real mediaMatriz( real m[2][3] )
{
inteiro i, j;
real media \ufffd\ufffd\ufffd\ufffd 0;
para ( i \ufffd\ufffd\ufffd\ufffd 0; i < 2; i \ufffd\ufffd\ufffd\ufffd i + 1) faça
{
para (j \ufffd\ufffd\ufffd\ufffd 0; j < 3; j \ufffd\ufffd\ufffd\ufffd j + 1) faça
{
media \ufffd\ufffd\ufffd\ufffd media + m[i][j];
}
}
retorne media/6.0;
}
principal