Divisible subarrays(I don't Know why ans is getting zero)

Hi @Saksham12
Error is in line 19.
It should be sum=(sum+n)%n;
Your code was showing wrong ans because you were adding sum to (sum+n)%n which was making it exceed value n and when you were computing ans then all the values were present at index greater than n thereby giving the ans as 0.