This line declares the variables
num
,
sum
, and
a
and initialises
a
with zero but the value of
num
and
sum
is undefined.
int num,sum,a=0;
While
num
and
a
are assigned later by code, there is no value assigned to
sum
but the actual value is used.
So you should change your code to (splitted into multiple lines here):
int num = 0;
int sum = 0;
int a = 0;