0
Question:
Create two vectors with size 5 and a size 10 vector;
Fill the two size 5 vectors with integers inserted keyboard;
After filling the two vectors of 5 positions their content should be passed to the vector of 10 positions so that:
Use a repeat loop in reading and passing values;
The contents of the first vector should be in positions 0, 2, 4, 6, 8;
The contents of the second vector should be in positions 1, 3, 5, 7, 9.
I just don’t know how to pass these two size 5 vectors in those size 10 vector positions.
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(){
int vet1[5], vet2[5], vet3[10];
for (int i=0; i<5; i++){
//cout << "Primeiro vetor de tamanho 5: \n";
cout << "Informe um valor: ";
cin >> vet1[i];
}
for (int i=0; i<5; i++){
//cout << "\nSegundo vetor de tamanho 5: \n";
cout << "Informe um valor 2: ";
cin >> vet2[i];
}
Hi Magazak, all right? As this has college exercise face I will try to help you with the problem without giving the final solution. If you need more help tell me. The secret of this exercise is that you need to make a decision within the loop. Even indexes (ie where
i % 2 == 0
) shall be read fromvet1
while odd indices should be read fromvet2
. Another issue is that you need to map the indexes between 0 and 9vet3
for their indices between 0 and 4vet1
andvet2
. You can do it by splittingi
for two, e.g.vet3[i] = vet1[i / 2]
.– Anthony Accioly
Or, do the 0 to 4, and put the vet1 and vet2 elements in 2i and 2i + 1 of vet3...
– hkotsubo
An alternative is to do:
for (i=0; i<5;i++) { vet3[2*i] = vet1[i]; vet3[2*i+1] = vet2[i];}
.– anonimo
Thank you all so much for your help, I got it
– magazak12
Nick looks like my hein kkkk
– user187043
Really? Kkkkkkk what is your?
– magazak12