Needing Help in Vector C Exercises

Asked

Viewed 51 times

0

Why aren’t you showing the 15 numbers? And how to include 3 numbers at the beginning of this vector?

int main()
{

   int v[30];
   int i,x;

   for(i=0; i < 15; i++)
   {
       printf("Digite 15 numeros");
       scanf("%d", &v[i]);
   }
   printf("%d Os numeros escolhidos foram:", v[i]);

}

1 answer

1


Just putting v[i] in print, you cannot print because you are not indicating which is the index i. To print all you must make a loop the same way you did to read, but with a printf instead of scanf:

for(i=0; i < 15; i++){
    printf("%d\n", v[i]);
} 

I just did that and spun it. (I also added the include <stdio.h> at the beginning of the file but I suppose you’ve already put).

inserir a descrição da imagem aqui

  • And how do you add 3 numbers at the beginning of this vector? , obg for the first answer

  • Just put the number in the index you want, like this: v[0] = 20; v[1] = 21; v[2] = 22;

  • 1

    Oh understood now, you want to add three more numbers but keep the ones that were already? for this I believe that I have to shift the current numbers to other positions, type v[3] = v[0]; v[4] = v[1]; v[5] = v[2]; (but you have to do this for all elements of the vector, then you can do a for with v[i+3] = v[i];) then you can put new values in the first positions.

Browser other questions tagged

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