Integer and Float Division
Dividing two ints drops the fraction. Cast one to double for a decimal result.
Example
#include <stdio.h>
int main(void) {
int a = 7, b = 2;
printf("%d %d %.2f\n", a / b, a % b, (double) a / b);
return 0;
}Result
3 1 3.50
Exercise
Remainder.
7 2
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.