Buscar

Ordenacao_(Com_Subalgoritmo)_Prof_Eolisses

Prévia do material em texto

Algoritmo: G:\Estudos\02 - Faculdade IESPLAN\Aulas\Aula 06 - 30 maio\Ordenacao_por_valor_re
ferencia.alg
Data: 07/06/2012
 1 algoritmo "Ordenacao_Com_Subalgoritmo"
 2 // Faculdade IESPLAN
 3 // Curso de Engenharia Civil
 4 // Disciplina: Métodos Computacionais
 5 // Autor : Prof. EOLISSES F. LEOPOLDINO
 6 // Data : 27/05/2012
 7 var
 8 nr1, nr2, nr3, nr_menor: inteiro
 9 op : caracter
 10 sair : logico
 11 //======================================================
 12 funcao Menor(x, y: inteiro): inteiro
 13 inicio
 14 se (y < x) entao
 15 x <- y
 16 fimse
 17 retorne x
 18 fimfuncao
 19 //=====================================================
 20 procedimento Troca(var x, y: inteiro)
 21 var
 22 aux : inteiro
 23 inicio
 24 aux <- x
 25 x <- y
 26 y <- aux
 27 fimprocedimento
 28 //=====================================================
 29 procedimento InsereLinhas(total_linhas: inteiro)
 30 var
 31 aux: inteiro
 32 inicio
 33 aux <- 1
 34 enquanto (aux <= total_linhas) faca
 35 escreval("")
 36 aux <- aux + 1
 37 fimenquanto
 38 fimprocedimento
 39 //=====================================================
 40 inicio
 41 repita
 42 escreva("Entre com 3 números inteiro:")
 43 InsereLinhas(3)
 44 //-------
 45 escreva("Nr 1: ")
 46 leia(nr1)
 47 //-------
 48 escreva("Nr 2: ")
 49 leia(nr2)
 50 //-------
 51 escreva("Nr 3: ")
 52 leia(nr3)
 53 //-------
 54 InsereLinhas(2)
 55 //-----------------------
 56 nr_menor <- Menor(nr1, nr2)
 57 se (nr1 <> nr_menor) entao
 58 Troca(nr1, nr2)
 59 fimse
 60 //-----------------------
 61 nr_menor <- Menor(nr1, nr3)
 62 se (nr1 <> nr_menor) entao
 63 Troca(nr1, nr3)
 64 fimse
 65 //------------------------
 66 nr_menor <- Menor(nr2, nr3)
 67 se (nr2 <> nr_menor) entao
 68 Troca(nr2, nr3)
 69 fimse
 70 //------------------------
 71 escreva("Sequencia ordenada: ", nr1, " - ", nr2, " - ", nr3)
 72 //----------
 73 InsereLinhas(2)
 74 //----------
 75 escreva("Testar novamente? <SIM>-S <NÃO>-N :")
 76 leia(op)
 77 se (op = "s") ou (op = "S") entao
 78 sair <- FALSO
 79 senao
 80 sair <- VERDADEIRO
 81 fimse
 82 //----------
 83 limpatela
 84 //----------
 85 ate sair = VERDADEIRO
 86 fimalgoritmo
 87

Outros materiais