### Help with a exercise (with code)

how do I check the value in a vector?
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` `````` #include #include #include using namespace std; int verifica (int x){ int N; for } }while(nota<0||nota>10); return nota; } int main(){ int N; cout<<"informe o tamanho do vetor: "; cin>>N; int vet[N];//criando vetor de tamanho variável int i,j,aux; srand(time(NULL)); for(i=0;ivet[j]){ aux=vet[i]; vet[i]=vet[j]; vet[j]=aux; } } } //mostra for(i=0;i
Last edited on
What do you mean by "check the value"?
check a value in the vector for dont show equal numbers
Last edited on
Do you mean checking if two vectors are equal, or if any two numbers in a single vector are equal?
checking if any two numbers in a single vector are equal
Iterate through the vector comparing each element with all elements after it; if at any point they are equal, then the vector contains two numbers that are equal. If you make it through without that happening, then all the elements are distinct.
Could you give me an example using a code?
To do Zhuge's suggestion, all you need to do is something like this:

 ``12345678910`` ``````for(i = 0;i < yourvectorname.size();++i) { for(j = i + 1;j < yourvectorname.size();++j) { if(yourvectorname.at(i) == yourvectorname.at(j)) { std::cout << "Two elements with the same value found at " << i << " and " << j << "!\n"; } } }``````

A more pressing issue here is that you are NOT USING ANY VECTORS IN YOUR CODE ANYWHERE!
Last edited on
Topic archived. No new replies allowed.