0

How to get an array from user without knowing the number of elements in the array?

Array using C

29th Sep 2019, 2:37 PM
Hariprasad.A.P
5 odpowiedzi
+ 3
use dynamic array ...
29th Sep 2019, 4:53 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 2
The user have to enter number of elements and then enter the values. Java: Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = scan.nextInt(); }
29th Sep 2019, 3:02 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
On C++ use vectors.
29th Sep 2019, 4:36 PM
Nboumakis
+ 2
Use ArrayList in Java
29th Sep 2019, 7:56 PM
Yashkin Oleg
Yashkin Oleg - avatar
+ 1
This code allocate and reallocate a buffer (C-String) as necessary to allow dynamically sized input. Maybe you can expand from the idea, and adjust to your fits. https://code.sololearn.com/cViPoPhBTG48/?ref=app
29th Sep 2019, 4:01 PM
Ipang