Explain the OUTPUT ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 18

Explain the OUTPUT ?

int main(){ int a=10,b=-3; int ans=a/b; cout<<ans<<endl; ans=a%b; cout<<ans<<endl; return 0; } OUTPUT: -3 1

20th Nov 2019, 10:35 AM
ROHIT KANOJIYA
ROHIT KANOJIYA - avatar
3 Answers
+ 14
ROHIT KANOJIYA⚔️🇮🇳{€X∆M$}🇮🇳⚔️ In C, C++ language with a remainder operator, the sign of the result is the same as the sign of the dividend. So 10 % 3 = 1 -10 % 3 = -1 10% -3 = 1 -10 % -3 = -1  Now, you can analyze when dividend is positive the answer will be positive else vice versa
20th Nov 2019, 10:49 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 8
10/-3=-3...because the operator gives only the quotient.. Now 10%3=1 becaz the modulo operator just gives the remainder after complete division...☺
21st Nov 2019, 1:29 AM
Devi Kamaraj..😉
Devi Kamaraj..😉 - avatar
+ 2
because you used int for a and b, thats why it gives you only -3
26th Nov 2019, 7:04 PM
A S
A S - avatar