logo

CuriousTab

CuriousTab

Discussion


Home C Programming Floating Point Issues See What Others Are Saying!
  • Question
  • Which of the following statement obtains the remainder on dividing 5.5 by 1.3?


  • Options
  • A. rem = (5.5 % 1.3)
  • B. rem = modf(5.5, 1.3)
  • C. rem = fmod(5.5, 1.3)
  • D. Error: we can't divide

  • Correct Answer
  • rem = fmod(5.5, 1.3) 

    Explanation
    fmod(x,y) - Calculates x modulo y, the remainder of x/y.
    This function is the same as the modulus operator. But fmod() performs floating point divisions.

    Example:

    
    #include <stdio.h>
    #include <math.h>
    
    int main ()
    {
      printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
      return 0;
    }
    

    Output:
    fmod of 5.5 by 1.3 is 0.300000


    More questions

    • 1. Bitwise & can be used to check if more than one bit in a number is on.

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. It is necessary that a header files should have a .h extension?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. Bitwise | can be used to set multiple bits in number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 5. Bitwise & can be used to check if a bit in number is set or not.

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. A pointer union CANNOT be created

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      int main()
      {
          union test
          {
              int i;
              float f;
              char c;
          };
          union test *t;
          t = (union test *)malloc(sizeof(union test));
          t->f = 10.10f;
          printf("%f", t->f);
          return 0;
      }
      

    • Options
    • A. 10
    • B. Garbage value
    • C. 10.100000
    • D. Error
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int x=4, y, z;
          y = --x;
          z = x--;
          printf("%d, %d, %d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. 4, 3, 3
    • B. 4, 3, 2
    • C. 3, 3, 2
    • D. 2, 3, 3
    • Discuss
    • 9. Functions cannot return a floating point number

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int a=100, b=200, c;
          c = (a == 100 || b > 200);
          printf("c=%d\n", c);
          return 0;
      }
      

    • Options
    • A. c=100
    • B. c=200
    • C. c=1
    • D. c=300
    • Discuss


    Comments

    There are no comments.

Enter a new Comment