|
|
|
|
|
by inetknght
906 days ago
|
|
cnt += a[i] No, you've changed the right-hand side expression. Now you're adding a[i] to cnt and nowhere has it stated that a[i] is 1. But a[i] > 0's result is always zero or one. I suggest what you want is this: cnt += !!a[i]
Now, a[i] is not-notted -- the expression returns a bool indicating whether the value is converted to true.or this, depending on your style: cnt += bool(a[i])
which does the same thing |
|