Programming Fundamentals/Functions/C
Appearance
(Redirected from Computer Programming/Subroutines/C)
functions.c
[edit | edit source]// This program asks the user for a Fahrenheit temperature,
// converts the given temperature to Celsius,
// and displays the results.
//
// References
// https://www.mathsisfun.com/temperature-conversion.html
// https://en.wikibooks.org/wiki/C_Programming
#include "stdio.h"
float get_fahrenheit();
float calculate_celsius(float fahrenheit);
void display_result(float fahrenheit, float celsius);
int main(void)
{
float fahrenheit;
float celsius;
fahrenheit = get_fahrenheit();
celsius = calculate_celsius(fahrenheit);
display_result(fahrenheit, celsius);
return 0;
}
float get_fahrenheit()
{
float fahrenheit;
printf("Enter Fahrenheit temperature:");
scanf("%f", &fahrenheit);
return fahrenheit;
}
float calculate_celsius(float fahrenheit)
{
float celsius;
celsius = (fahrenheit - 32) * 5 / 9;
return celsius;
}
void display_result(float fahrenheit, float celsius)
{
printf("%f° Fahrenheit is %f° Celsius", fahrenheit, celsius);
}
Try It
[edit | edit source]Copy