0
How its output is 2 but not 3
https://sololearn.com/compiler-playground/cZYpimiQ52zJ/?ref=app
5 Respostas
+ 6
Hi! 5/2 is 2.5, not 3. You're most likely getting the result 2 because you declared your variables a and b as int at the beginning. An int is an integer, and the fractional part is discarded. If you want to get 3, declare the variables as float (double) and round the result up at the end of the calculation. If you want an exact result, declare the variables as floating-point numbers.
+ 4
integer division in C truncates, it does not round.
so 2.1, 2.5, or 2.9 all becomes 2
the numbers after the decimal point are just dropped, they're not rounded.
+ 4
https://sololearn.com/compiler-playground/clcr05N0JtlC/?ref=app
note that C's round does not follow the standard rounding rule of 'round half to even' for 0.5 (which should round up ony if the preceeeding number is odd). 2.5 rounds to 3.0 instead of 2.0
in python, round is to the nearest even value:
print(round(5/2)) # 2.5 rounded to 2
print(round(7/2)) # 3.5 rounded to 4
round in C, C++ and Go
https://sololearn.com/compiler-playground/cWt2POjvZMee/?ref=app
https://sololearn.com/compiler-playground/cXnGEuCbShU2/?ref=app
0
bcz 1 +1 is 2 ydot
0
I'd like to invite you to join our vibrant community of programmers on WhatsApp!
Our group is dedicated to helping each other with coding challenges, sharing knowledge, and learning from industry experts. Whether you're a beginner or an experienced developer, you'll find valuable resources, support, and camaraderie here.
Join us to:
- Get help with coding problems and challenges
- Share your expertise and learn from others
- Stay updated on the latest programming trends and technologies
- Connect with like-minded developers and build meaningful relationships
Click this link to join our community
https://chat.whatsapp.com/FW0nBbr3Eug3oTiL1U53gR
Looking forward to coding, learning, and growing with you!"



