A
Q. Modulus for float could be achieved by?
- Correct Answer - Option(B)
- Views: 183
- Filed under category C Programming
A
In C, the modulus operator % only works with integer types (int, long, etc.). It does not work with floating-point numbers (float or double).
To find the remainder when dividing floating-point numbers, we use the fmod() function from the math.h library.
Syntax:
#include <stdio.h>
#include <math.h>
int main() {
double p = 5.5, q = 2.0;
double result = fmod(p, q);
printf("fmod(%.2f, %.2f) = %.2f\n", p, q, result);
return 0;
}
Output:
fmod(5.50, 2.00) = 1.50
Why Other Options Are Incorrect?
(A) mod(p, q); ❌
(C) modulus(p, q); ❌
(D) p % q ❌
Final Answer:
✅ fmod(p, q); is the correct way to get the modulus of floating-point numbers in C.
You must be Logged in to update hint/solution
Discusssion
Login to discuss.