0
Please give me clarity about %
3 Answers
+ 2
'%' symbol represents modulus operator . It returns the remainder of the two inputs .
example:-
{ int a,b,c;
c= a%b;
cout<<c;
}
now if a is 4 and b is 2 then , output is 0 .
But if a is 5 and b is 2 then output is 1 .
Hope it helps ..
Good Luck.
0
Just to add to the previous answer, a%b returns the remainder when a is divided by b
if
a = qb + r
where 0 <= r < n
Then a % b = r
I think some languages deal with it differently for negative numbers, the normal mathematical definition keeps r as positive, whereas I think Java doesn't