Reading a sequence between 2 and a certain value of x

1
Good afternoon, I would like to know how I can create a vector that stores a sequence, that is, if I want the numbers between 2 and the user between x = 10, the values inside the vector are as vector [2, 10 ] = 2,3,4,5,6,7,8,9,10 ??

    
asked by anonymous 24.04.2015 / 20:43

1 answer

3

Considering that x is the number supplied by the user:

j = 0;  //variavel que será responsável pelo indice do vetor

for (int i=2; i<=x; i++) {
    vetor[j] = i;
    j++;
}

In this way, as the loop is executed, the vector will be organized as follows for x = 4, for example:

  

vector [0] = 2;   vector [1] = 3;   vector [2] = 4;

    
24.04.2015 / 20:55