I'm currently reading the K&R Book on C, I'm currently doing the temperature converter code and it says here that cels = 5 * (fahr-32) / 9; instead of just multiplying it by 5/9 we multiply by 5 and then divide by 9 since it truncates, but my code doesn't truncate it am I doing something wrong or is this a new feature in Modern C? here is my code
#include <stdio.h>
int main(){
int fahr, cels;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (fahr <= upper) {
cels = (fahr - 32) * 5/9;
printf("%d\t%d\n", fahr, cels);
fahr = fahr + step;
}
}
Edit:
Instead of cels = (fahr - 32) * 5/9; I did cels = 5/9 *(fahr - 32); and it truncates the code. Why does the other one work while the other does not?