AULA 22 - 06/07/2011 - Exercicios
Autor: Maike Nunes | Publicado: 2011-07-11T21:45:00-07:00

&nbsp; Na aula de hoje o professor Jossandro corrigiu as questões da aula anterior, e passou mais 3 questões que disponibilizarei a seguir.
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.
&nbsp;algoritmo "multi_maior_1"
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
Download arquivo alg. 
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 "aula22_ex2"
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; para i &lt;- 1 ate 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
Download arquivo alg. 
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 "minmax3"
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;&nb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lt;- mat[linha,i]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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
Download arquivo alg. 
&nbsp;Como sempre a lógica sempre dificulta,&nbsp; na questão 2 tive grande dificuldade na compreensão do exercício, mas o professor Jossandro me explicou e acabei compreendendo, as outras duas tive uma certa facilidade em soluciona-las, mesmo o MINMAX da questão 3 e a multiplicação da matriz pelo maior elemento da questão 1 sendo a principio confusos. Mas depois que conseguimos nos concentrar com certeza todos eles ficam mais&nbsp;fáceis..