Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CPP - Arrays - Ex.2 - Solution
//Write a program which takes 2 arrays of 10 integers each, a and b. c is an array with 20 integers. //The program should put into c the appending of b to a, the first 10 integers of c from array a, the latter 10 from b. Then the program should display c. #include <iostream> #define numberOfElementsAB 10 #define numberOfElementsC 20 using namespace std; void acquireArray(int array[numberOfElementsAB]); void concatArrays(int a[numberOfElementsAB], int b[numberOfElementsAB], int c[numberOfElementsC]); void printValues(int numbers[numberOfElementsC]); int main() { int a[numberOfElementsAB]; int b[numberOfElementsAB]; int c[numberOfElementsC]; acquireArray(a); acquireArray(b); concatArrays(a, b, c); printValues(c); } void acquireArray(int array[numberOfElementsAB]) { cin >> array[0] >> array[1] >> array[2] >> array[3] >> array[4] >> array[5] >> array[6] >> array[7] >> array[8] >> array[9]; } void concatArrays(int a[numberOfElementsAB], int b[numberOfElementsAB], int c[numberOfElementsC]) { for(int i=0; i < numberOfElementsAB; i++) { c[i] = a[i]; } for(int i=0; i < numberOfElementsAB; i++) { c[i + numberOfElementsAB] = b[i]; } } void printValues(int numbers[numberOfElementsC]) { for(int i=0; i < numberOfElementsC; i++) { cout << " " << numbers[i]; } }
run
|
edit
|
history
|
help
0
Pairs having sum equal to target
MapTel2
Size of data type test
Avoiding visited networked paths
Travel Buddy
work
role of copy constructor
MyStack
fibonacci
3 and 7 in a row