3 Years
Discussion Span
Last Post by rajii93

why it gives 10 again instead of 0 remainder


To expand Mochops answer a little: The modulus operator '%' divides the number to its left, by the number to its right and returns the remainder.

As moschops pointed out 10%20 is 10.
Because 10 divides by 20 zero times, leaving a remainder of 10.

Whereas 20%10 is 0.
Because 20 divides by 10 twice, leaving a remainder of 0.


The sarcasm of my colleagues notwithstanding, my magic wand stopped working this morning. :-) Learn by doing, reading, and studying the works of others who are known to be competent in the field. Best single C++ reference work? The ARM (Annotated Reference Manual) by Ellis and Stroustrup. Stroustrup invented the language, so he must know something about it...


For a second there I thought I was in The Matrix (TM).

I know Kung-fu.

Votes + Comments
I know aikido - does that count? :-)
 Here in this code you will get the output as the remainder.That is, for example 10/5 implies output(quotient)=2,where as 10%5 implies output(remainder)=0. I think you get a better idea about %.similar to the example 10/20=0(since i is an integer,if i is float 10/20=0.5)and** 10**%20 yields the same **10 **(as 10 is smaller than 20)if 30%20 implies output 10 as 30 has one 20 in it q=1,(30-20=10)r=10.And when 20%20 yields output of 0(r) where 20/20 yields output 1(q).Hope u understand the difference between divide(/)[which yields output as quotient(q) and modulus(%)[which yields output as remainder(r)].
Votes + Comments
The original question/post was "make me good in c++". The only remainder I can see is the rest of the poster's career... :-)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.