make me good in c++

i=10;
i=i%20;
why it gives 10 again instead of 0 remainder

Because 10%20 is 10

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...

Member Avatar for iamthwee

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

I know Kung-fu.

commented: I know aikido - does that count? :-) +12
 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)].
commented: The original question/post was "make me good in c++". The only remainder I can see is the rest of the poster's career... :-) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.