Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int bigSize{ 10 };
- const int smallSize{ bigSize / 2 };
- int bigArr[bigSize];
- int smallA[smallSize];
- int smallB[smallSize];
- for (int method{ 2 }; method; --method) //2 - A, 1 - B
- {
- // fill and output bigArr
- std::cout << "bigArr: ";
- for (int bigIdx{ 0 }; bigIdx < bigSize; ++bigIdx)
- {
- bigArr[bigIdx] = rand() % 10;
- std::cout << bigArr[bigIdx] << ' ';
- }
- std::cout << '\n';
- // copy from bigArr to two smallA and smallB array
- // there are two methods to copy - A and B
- if (method == 2)
- {
- // method A
- for (int smallIdx{ 0 }; smallIdx < bigSize; ++smallIdx)
- {
- (smallIdx < smallSize ? smallA[smallIdx] : smallB[smallIdx - smallSize]) = bigArr[smallIdx];
- }
- }
- else
- {
- // method B
- for (int smallIdx{ 0 }; smallIdx < smallSize; ++smallIdx)
- {
- smallA[smallIdx] = bigArr[smallIdx];
- smallB[smallIdx] = bigArr[smallSize + smallIdx];
- }
- }
- std::cout << "smallA: ";
- for (int smallIdx{ 0 }; smallIdx < smallSize; ++smallIdx)
- {
- std::cout << smallA[smallIdx] << ' ';
- }
- std::cout << '\n';
- std::cout << "smallB: ";
- for (int smallIdx{ 0 }; smallIdx < smallSize; ++smallIdx)
- {
- std::cout << smallB[smallIdx] << ' ';
- }
- std::cout << '\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment