-1
I have a vector q will be filled by 6 random values and need to check if there are numbers in sequence in the vector. How would you do this ?
-1
I have a vector q will be filled by 6 random values and need to check if there are numbers in sequence in the vector. How would you do this ?
0
Good evening, you can after assigning the value Random, compare to see if the previous + 1 is equal
for(int i = 0; i<6; i++)
{
//Nao lembro como usar o rand em c mas acho que e assim
vetor[i] = rand();
if((i>0) && ((vetor[i-1]+1) == vetor[i]))
{
printf("número sequencial");
}
}
printf("nenhum numero sequencial");
This way you can get sequences like 14579(4 and 5 sequential) That check of i>0 is because if it is 0 it will turn a -1 in the other condition and would give error in the vector I was wrong to do it in c, but if you can understand the logic is the same. Good luck there, I hope I helped
For this to work you need to sort the vector before doing the check.
Browser other questions tagged c visualg
You are not signed in. Login or sign up in order to post.
What do you mean in sequence? For example: 0 ,1 ,2 ,3 ...
– SeventhBit
That’s right 0,1,2,3...
– Rodrigo Peralta
If in sequence what is to be done?
– SeventhBit