Tengen Toppa Gurren Lagann

Greenhorn

Posts: 1

posted 3 years ago

Because that's how the '%' operator works. You might also want to try it with negative values and see what it produces - you may be surprised.

Not quite sure what you want here, but the simple answer is: Because it's what you told it to do.

Perhaps you could show us what you

Winston

Tengen Toppa Gurren Lagann wrote:i'm confused about the if statement part becauseint i = 0is set to zero but how can you get the remainder ifint iis zero?

Because that's how the '%' operator works. You might also want to try it with negative values and see what it produces - you may be surprised.

And also please explain to why it output like this?

Not quite sure what you want here, but the simple answer is: Because it's what you told it to do.

Perhaps you could show us what you

*expected*to see. That might help us to clear up your problem.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

posted 3 years ago

- 1

at a basic level, mathematical (as opposed to computer) integer division returns two whole numbers. one is how many times 'a' goes into 'b', and one is how many are left over. Or, how many times can you subtract a from b before you don't have enough to pull out any more, and then what's left over.

so, 13 divided by 4 would give you 3-remainder-1. you can pull 4 out of 13 three times, and you would have one left over.

31 divided by 7 gives you 4 remainder 3, etc.

so...

0 divided by 12 - you can pull 12 out of 0 exactly ZERO times, and you have ZERO left over.

so, 13 divided by 4 would give you 3-remainder-1. you can pull 4 out of 13 three times, and you would have one left over.

31 divided by 7 gives you 4 remainder 3, etc.

so...

0 divided by 12 - you can pull 12 out of 0 exactly ZERO times, and you have ZERO left over.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors