I have the following exercise:
Only using For - While - If - Switch Case - Vectors - Printf - Scanf - Int - Char
It will work with two vectors, where the length of the vector must be given by the user by keyboard (int longVector). Once the user defined the length of the vectors, the first vector is loaded (vector1), the user must load by keyboard each whole number that forms the vector. When we have the vector1 loaded with the numbers of the user, for example vector1 = {1,4,5,3,6}, the vector vector2 must be created, with the numbers all inverted, that is, for example, vector2 = { 6, -3.5.4.1}.
B- Show on screen both vectors in two different lines with this format per console: Vector 1 is formed by the numbers: 1 4 5 -3 6 And vector 2 is formed by the numbers: 6 -3 5 4 1.
I'm a beginner, and I got to do it up here:
int main()
{
int i=0;
int j=0;
int largovector=0;
int vector1[largovector];
int vector2[largovector];
printf("Ingrese el largo del vector\n"); //Definimos el largo del vector
scanf("%d",&largovector);
for(j=0; j<largovector; j++) //Definimos los numeros del vector
{
printf ("Ingrese el valor de la coordenada %d del vector: \n",j);
scanf ("%d",&vector1[j]);
}
printf("El vector 1 esta formado por los numeros: ");//Imprimimos el vector
for(j=0; j<largovector; j++)
{
printf("%d ",vector1[j]);
}
printf("\n");
printf("El vector 2 esta formado por los numeros: ");
for (i=largovector-1; i>=0; i--)
{
printf("%d ",&vector2[j]);
}
return 0;
}
My problem is that I do not know how to create a Vector2[]
that has the same coordinates as the Vector1
to create the inverse. How could I do it?