0

Please give me clarity about %

15th Jan 2018, 6:08 PM
Mohamed khalid
Mohamed khalid - avatar
3 Respostas
+ 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.
15th Jan 2018, 6:34 PM
Ashutosh Pandey
Ashutosh Pandey - avatar
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
15th Jan 2018, 8:03 PM
Dan Walker
Dan Walker - avatar