Vector issue portugol

Asked

Viewed 485 times

2

Two questions about vectors and matrices. 1_Dado any vector with 100 integers, make a module that tells if there is or not repeated numbers on this vector.

Algorithm "Repetition in the vector"

Var
// Seção de Declarações das variáveis 
vet : vetor [1..10] de inteiro
i,j, aux: inteiro
rep: inteiro

Inicio
// Seção de Comandos, procedimento, funções, operadores, etc... 
para i de 1 ate 10 faca
leia (vet[i])
fimpara

para i de 1 ate 9 faca
para j de i ate 10 faca
     se vet[j] < vet[i] entao
        aux <- vet[j]
        vet[j] <- vet[i]
        vet[i]<- aux
     fimse
fimpara
fimpara
para i de 1 ate 10 faca
escreva (vet[i])
fimpara
rep<- (vet[1])
 para i de 1 ate 10 faca
      se (vet[i] = rep) entao
         escreva ("O numero", rep," está repetido.")
      fimse
 fimpara

Fimalgoritmo

// in this algorithm unfortunately it only points if it has only 1 repeated number.

2_Dado an array of 20 real numbers and a 20x20 matrix of real numbers, enter which ones rows and columns are equal to the vector, either in the given order or in reverse order. Assume that there must be a row or column equal to the vector in the matrix.

  • 1

    What have you tried to do? It would be interesting to add your attempt to the pegunta by clicking on [Dit]

  • Okay, sorry, I’m new here :)

1 answer

1

If you want to see the amount of repeated numbers, you will need to make a variable cont.

To store the repeated numbers you can make an extra vector and store them there.

That part:

    se vet[j] < vet[i] entao
    aux <- vet[j]
    vet[j] <- vet[i]
    vet[i]<- aux
    fimse

(you don’t need to sort just see if it repeats)

Creates a variable k.

    k:inteiro
    vet2 : vetor [1..10] de inteiro

    k<-1
    para i de 1 ate 10 faca
    para j de 1 ate 10 faca
    se vet[j] = vet[i] entao
    vet2[k]<-vet[j]
    k=k+1

   fimse
   fimpara
   fimpara
    //depois realiza um laço para escrever o vetor k na qual 

Browser other questions tagged

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