"I am trying to find the size of the 'list[34]' array but it is being set by random numbers when the program is being initialised. I cannot remove the rand() function in main because that is part of the question and is just added back in by the solution checker when I submit.
I have tried setting all the values in the array to '0' but that throws out the 'list_size' variable if the list is shorter than 35 values since the list is just filled with whatever is parsed into it followed by '0' in all other values.
#include <stdlib.h>
#include <float.h>
// Declare Global variables here.
double list[34];
int list_size;
void array_stats() {
// Insert your solution here.
for(int i = 0; i <= 35; i++)
{
scanf("%lf", &list[i]);
list_size = i;
if (list[i] == 0)
{
break;
}
}
}
#include <stdlib.h>
#include <time.h>
int main() {
// Simulate the test setup process.
srand( time( NULL ) );
for ( int i = 0; i < 34; i++ ) {
list[i] = rand();
}
list_size = rand();
// Call submitted code.
array_stats();
// Display contents of array list.
for (int i = 0; i < list_size; i++) {
printf("%f ", list[i]);
}
printf("\n");
printf("Item count: %d\n", list_size);
return 0;
}```
Expected result for an empty string (echo '' | file_name) is 0
Actual result for an empty string (echo '' | file_name) is 34