27th Oct 2025, 5:32 AM
Axxcii
Axxcii - avatar
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.
27th Oct 2025, 5:57 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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.
27th Oct 2025, 5:49 AM
Bob_Li
Bob_Li - avatar
+ 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
27th Oct 2025, 6:00 AM
Bob_Li
Bob_Li - avatar
0
bcz 1 +1 is 2 ydot
28th Oct 2025, 3:45 AM
ACE LIM ZHAO PENG
ACE LIM ZHAO PENG - avatar
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!"
28th Oct 2025, 6:13 AM
Precious
Precious - avatar