Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
CPP - Arrays - Ex.2 - Solution
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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]; } }
g++
1 2 3 4 5 5 7 8 9 10 11 12 13 24 15 16 17 18 19 20
Show compiler warnings
[
+
] Compiler args
[
-
]
Show input
Compilation time: 0.44 sec, absolute running time: 0.04 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.49 sec
edit mode
|
history
|
discussion