0

My code for the following simple coding exercise produces a "division by zero" warning, and I'm wondering why.

#include <stdio.h>

int main() {

  for(int i = 0; i < 100; i++) {
    printf("celsius=%d fahrenheit=%d\n", i, (i/(5/9))+32);
  }

  return 1;

}
temps.c: In function ‘main’:
temps.c:6:45: warning: division by zero [-Wdiv-by-zero]
     printf("celsius=%d fahrenheit=%d\n", i, (i/(5/9))+32);

1 Answers1

1

I realised while writing this question that it's because I should have written 5.0/9.0, since C handles division with integers in a way that I didn't expect. Posting this anyway since I couldn't find this particular error linked to this particular problem on SO.