let’s walk through your code:
malloc(sizeof(int) * num)
, what is the value ofnum
?scanf("%d",num)
, check the return value ofscanf
( number of element successfully parsed byscanf
)for( i = 0 ; i < num; i++ )
, loop withi
from0
tonum
scanf("%llu",&num_alloc[num])
, read number and store it innum_alloc[num]
( indices of array in C start from0
)FinalSum = FinalSum + num_alloc[num]
, addnum_alloc[num]
toFinalSum
( 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.