/* * question8a.c * FINAL * By: John Stile * Summery: Convert a fahrenheight to celcius */ #include float * f2c(float); // prototype for f2c. takes float returns pointer to a float. int main(void) { float fahr; // declare float named fahr float *cel; // delcare float pointer cel printf("This program converts fahrenheight[F] to celsius[c].\n"); // introduction printf("Enter a temp in fahrenheit: "); // prompt for input scanf("%f", &fahr); // read floating point number from stdin, // store in address of fahr cel=f2c(fahr); // call funciton f2c, passing it value stored in fahr // assign return to address stored in float pointer cel. printf("The %.1f F is %.1f C\n", fahr, *cel); // print contents of fahr // and value at address pointed to by cel return 0; // return 0 to calling shell } float * f2c(float f) // header for f2c. assigns passed value to float f // funciton returns pointer to float { float c; // declare float named 'c' float *pc; // declare float pointer named pc pc = &c; // assign address of variable c to pointer pc c = (f - 32)*5.0/9; // subtract 32 from value of f, multiply by 5.0, and divide result by 9. return pc; // return pointer pc to caller }