logo

CuriousTab

CuriousTab

Discussion


Home Technical Questions Programming See What Others Are Saying!
  • Question
  • We want to round off x, a Float to an Int value. The correct way to do so would be


  • Options
  • A. Y = ( int ) ( x + 0.5 ) ;
  • B. Y = int ( x + 0.5) ;
  • C. Y = ( int ) x + 0.5;
  • D. Y = ( int ) ( ( int ) x + 0.5 )

  • Correct Answer
  • 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


  • More questions

    • 1. What does microprocessor speed depend on?
    • Discuss
    • 2. What does RSI stand for?
    • Discuss
    • 3. Which Stack is used in 8086?
    • Discuss
    • 4. What is object repository?
    • Discuss
    • 5. Which is the Stack used in 8085?
    • Discuss
    • 6. What does GUI stand for?
    • Discuss
    • 7. What is the main reason the OSI Model was created?
    • Discuss
    • 8. Ethernet uses which topology

    • Options
    • A. Star
    • B. Bus
    • C. Twisted pair
    • D. Both B & C
    • Discuss
    • 9. What are various scheduling queues?
    • Discuss
    • 10. What is the state of the processor, when a process is waiting for some event to occur?
    • Discuss


    Comments

    There are no comments.

Enter a new Comment