AULA 22 - 06/07/11 - EXERCÍCIOS MATRIZES
Autor: Jefferson Figueiredo | Publicado: 2011-07-06T16:02:00-07:00

Na aula de hoje o professor Jossandro corrigiu as questões que ficaram pendentes da aula anterior, e nos passou mais 3 questões que seguem abaixo.
1) Faça um algoritmo que preencha uma matriz M (2x2), calcule e mostre a matriz R, resultante da multiplicação dos elementos de M pelo seu maior elemento.
algoritmo "maior"
var
&nbsp;&nbsp; m:vetor [1..2,1..2] de real
&nbsp;&nbsp; r:vetor [1..2,1..2] de real
&nbsp;&nbsp; maior,lim,col:real
&nbsp;&nbsp; n,i:inteiro
inicio
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para n de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para i de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Digite um número para linha ",n," e para coluna ",i,":")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(m[n,i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maior&lt;- m[1,1]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos&lt;- 1,1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para n de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para i de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se (maior &lt; m[n,i]) entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maior&lt;- m[n,i]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lim&lt;- n
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col&lt;- i
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("O número maior da matriz foi",maior)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para n de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para i de 1 ate 2 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r[n,i]&lt;- m[n,i] * maior
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("O resultado da multiplicação entre ",m[n,i]," e ",maior," foi ",r[n,i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
fimalgoritmo
2) Faça um programa que preencha:
Um vetor com oito posições, contendo nomes de      lojas;
Outro vetor com quatro posições, contendo      nomes de produtos;
Uma matriz com os preços de todos os produtos      em cada loja.

O programa deverá mostrar todas as relações (nome do produto – nome da loja) em que o preço não ultrapasse R$ 120,00.

algoritmo"loja"
var
&nbsp;loja:vetor[1..8]de caractere
&nbsp;prod:vetor[1..4]de caractere
&nbsp;preco:vetor[1..8,1..4]de real
&nbsp;i,j:inteiro
inicio
&nbsp;parai&lt;-1ate 8 faca
&nbsp;&nbsp;&nbsp; escreval("Digite o nome da loja ",i)
&nbsp;&nbsp;&nbsp; leia(loja[i])
&nbsp; fimpara
&nbsp; para i &lt;- 1 ate 4 faca
&nbsp;&nbsp;&nbsp; escreval("Digite o nome do produto ",i)
&nbsp;&nbsp;&nbsp; leia(prod[i])
&nbsp; fimpara
&nbsp; para i &lt;- 1 ate 8 faca
&nbsp;&nbsp;&nbsp; para j &lt;- 1 ate 4 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Digite o preco do(a) ",prod[j]," na loja ",loja[i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(preco[i,j])
&nbsp;&nbsp;&nbsp; fimpara
&nbsp; fimpara
&nbsp; para i &lt;- 1 ate 8 faca
&nbsp;&nbsp;&nbsp; para j &lt;- 1 ate 4 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se (preco[i,j] &lt;= 120) entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval(prod[j]," custa R$",preco[i,j]," na loja ",loja[i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse
&nbsp;&nbsp;&nbsp; fimpara
&nbsp; fimpara
fimalgoritmo

3) Na teoria dos sistemas, define-se o elemento MINMAX de uma matriz como o maior elemento da linha em que se econtra o menor elemento da matriz. Elabore um programa que carregue uma matriz 4x7 com números reais, calcule e mostre seu MINMAX e sua posição (linha e coluna).
&nbsp;algoritmo "minmax"
var
&nbsp;&nbsp; mat:vetor[1..4,1..7] de real
&nbsp;&nbsp; menor,maior,coluna,colunamaior,linha: real
&nbsp;&nbsp; n,i: inteiro
inicio
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para n de 1 ate 4 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para i de 1 ate 7 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("digite o número pertencente a coluna ",i," e a linha ",n,":")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(mat[n,i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; menor&lt;- mat[1,1]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linha&lt;- 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coluna&lt;- 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para n de 1 ate 4 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para i de 1 ate 7 faca
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se menor &lt; mat[n,i] entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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sp;&nbsp;&nbsp; colunamaior&lt;- i
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimpara
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("o menor número é ",menor," esta na linha ",linha,",e na coluna ",coluna," e o maior desta linha é ",maior," esta na coluna ",colunamaior)
fimalgoritmo
Na aula de hoje tive alguma dificuldade na resolução dos exercícios, após a explicação do professor acabei entendendo. &nbsp;Agora está acalmando o temor da matéria e dando para perceber onde estão os erros.