Question vector portugol

2

Two questions about vectors and matrices. 1_ Give any vector with 100 integers, make a module that informs whether there is or not repeated numbers in that vector.

Algorithm "Repeat in 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 you have only 1 number repeated.

2_ Given a vector of 20 real numbers and a 20x20 matrix of real numbers, rows and columns are equal to the vector, be it in the given order or in reverse order. Assume that there is a line or column equal to the vector in the array.

    
asked by anonymous 12.04.2016 / 17:35

1 answer

1

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

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

This part:

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

(You do not need to do sorting just see repeating)

Create 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 
    
20.10.2017 / 15:05