Algorithm that sorts decimal numbers

Asked

Viewed 61 times

0

People who can help me I am extremely grateful, I’m trying to build an algorithm that orders 3 real numerical values in ascending order, but not how to deal with decimal numbers in the algorithm...

var 

num: vetor[1..3] de inteiro
i, j, aux: inteiro

Inicio

 para i de 1 ate 3 passo 1 faca
      escreva ("Informe um número:")
      leia (num[i])
 fimpara

      para i de 1 ate 2 passo 1 faca
           para j de i+1 ate 3 faca
                se (num[i] > num[j]) entao
                   aux <- num[i]
                   num[i] <- num[j]
                   num[j] <- aux
                fimse
           fimpara
      fimpara

      para i de 1 ate 3 passo 1 faca
           escreva (num[i])
      fimpara
Fimalgoritmo

  • What environment are you programming in?

  • Being more specific, it is a work of the faculty, I am using Portugol (structured Portuguese). In other programming languages you could use the Sort() command, but since it does not exist in portugol I need to build something for this purpose.

1 answer

0


Substitute:

num: vetor[1..3] de inteiro

for:

num: vetor[1..3] de real

and place the aux variable also as real:

aux: real
  • Man, you saved me haha thank you so much !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.