let’s walk through your code:
malloc(sizeof(int) * num), what is the value of
scanf("%d",num), check the return value of
scanf( number of element successfully parsed by
for( i = 0 ; i < num; i++ ), loop with
scanf("%llu",&num_alloc[num]), read number and store it in
num_alloc[num]( indices of array in C start from
FinalSum = FinalSum + num_alloc[num], add
FinalSum( see #4 )
- end loop
I provided some advice to fix your code. But additionally do you need to store each values that are read until the end of the program ?
Also, ‘malloc’ is a function of ‘stdlib.h’ and you didn’t include that header file.