Code:
for(int b=1; b<=num; a++)
that should be b++