what’s the difference between:
sum=(sum+n)%n;
and
sum = sum%n;
sum = (sum+n)%n;
what’s the difference between:
sum=(sum+n)%n;
and
sum = sum%n;
sum = (sum+n)%n;
hi @Naman-Bansal-2736674666374052
using (sum+n)%n this will not give negative nos
suposse sum is -2 first make possitive by adding with n and then taking mod
but ans will not effect
you can check
sum = sum%n;
using this sum can be negative
what I wanted to ask was will there be any case for which the 2 set of statements will produce a different output ?
1st set
sum = (sum+n)%n;
2nd set
sum = sum % n;
sum = (sum + n)%n;
Ik it might seem like a silly question, but while solving one of the problems in the course assignments, one set of statement(s) was giving the correct answer while the other was giving wrong answer
okay i got your point @Naman-Bansal-2736674666374052
second Set is wrong
in second set
you are take mod and then adding n which will affect your answer
in the first set you are adding to sum and then with the same no you are taking mod so answer will not effect