Explain the OUTPUT ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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