+ 2
Your array was defined <size> elements, but you use <n> in your for loops. You need to change the for-loop condition. for( i = 0; i < size; i++ ) And also the second for-loop for( i = 1; i < size; i++ )
21st Dec 2020, 12:22 PM
Ipang
+ 1
Your "n" variable in the loops has not been initialised.
21st Dec 2020, 12:20 PM
rodwynnejones
rodwynnejones - avatar
0
I don't think it's possible to allocate memory for a[size] as well. You have to make this array dynamic by using pointer, and "malloc" in C, or "new" operator in C++, like this: int * a = malloc(sizeof(int)*size); // C int * a = new int[size]; // C++ You can use malloc in C++ as well.
21st Dec 2020, 1:11 PM
Michal Doruch