I'm trying to learn C on my own, at my own pace (as I never really grasped it while at college). I've been reading Ritchie & Kernighan's "The C Programming Language".
I made a short program to convert a range of Fahrenheit temperatures to Celsius. It seems to compile and run OK using gcc in Linux. I'm wondering if someone could 'critique' my code, let me know if I am doing anything wrong. In particular, is it safe to convert an int to a float, like I did below, where function 'celsius' takes an int and returns a float to main?
Code:
/*a wee program to convert a range of Fahrenheit temperatures
(-100 to 300 to be exact, in 20 degree increments) to Celsius*/
#include <stdio.h>
float celsius(int); /*function prototype*/
main()
{
int f;
for (f = -100; f <= 300; f = f + 20)
printf("%d\t%.2f\n", f, celsius(f));
return 0;
}
/*function celsius definition*/
float celsius(int f)
{
float c;
c = (5.0/9.0) * (f - 32.0);
return c;
}