0

i created a programe for printing all prime no between say 1 to 100 now i want to store all that in an array,how to do that?

only storing all that number in the array.

10th Aug 2016, 6:43 PM
Tarun kumar parashar
Tarun kumar parashar - avatar
5 Respuestas
+ 1
Push the numbers back into the array as you find them. Then iterate through the array to print or change it as needed. I generally use vectors and the syntax for that is: vector_name.push_back(value_name) I'm not sure if arrays use the same syntax as vectors, but you could try, if not try using a vector. Syntax: vector<int>vector_name{}; Or look through StackOverflow as I guarenttee you this question has probably been answered there.
10th Aug 2016, 8:31 PM
Donovan
Donovan - avatar
+ 1
arrays are immutable, you would need to use a vector or set the array to a fixed size beforehand arr[100] for example. alternatively keep allocating more memory and deleting the previous array.
10th Aug 2016, 9:08 PM
Nick
+ 1
arrays can't have numbers pushed into mr.robot
10th Aug 2016, 9:11 PM
destro
+ 1
Yeah i use vectors, not much knowledge on arrays in the c lang. Thanks for clearing that up, destro. I would use a vector then
10th Aug 2016, 9:20 PM
Donovan
Donovan - avatar
+ 1
no problem! usually I keep to this philosophy : known number of elements? array possibly more or less than needed? vector
10th Aug 2016, 9:21 PM
destro