Join ExamsbookAnswer : 1. "Y = ( int ) ( x + 0.5 ) ;"
We want to round off x, a Float to an Int value. The correct way to do so would be5
Q: We want to round off x, a Float to an Int value. The correct way to do so would be
- 1Y = ( int ) ( x + 0.5 ) ;true
- 2Y = int ( x + 0.5) ;false
- 3Y = ( int ) x + 0.5;false
- 4Y = ( int ) ( ( int ) x + 0.5 )false
- Show AnswerHide Answer
- Workspace
Answer : 1. "Y = ( int ) ( x + 0.5 ) ;"
Explanation :
Answer: A) Y = ( int ) ( x + 0.5 ) ; Explanation: Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number. y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int) Example: #include int main () { float x = 2.6; int y = (int)(x + 0.5); printf ("Result = %d\n", y ); return 0; } Result : 3