Question 3
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
double minutes = 135.5;
double rest = minutes % 60;
printf("%.1f\n", rest);
return 0;
}
- A 60 must be 60.0
- B The % operator requires integer operands; use fmod(minutes, 60) from <math.h> Correct
- C rest must be an int
- D There is no bug
Correct Answer: Option B
Even writing 60.0 does not help: % is not defined for floating types. fmod(135.5, 60) returns 15.5.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!