Programming Fundamentals/Functions/C: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 04:18, 19 January 2017

subroutines.c

#include "stdio.h"

float get_f();
float calculate_c(float f);
void display_result(float f, float c);

int main(void) 
{
    float f;
    float c;
    
    f = get_f();
    c = calculate_c(f);
    display_result(f, c);

    return 0;
}

float get_f()
{
    float f;
    
    printf("Enter Fahrenheit temperature:");
    scanf("%f", &f);

    return f;
}

float calculate_c(float f)
{
    float c;
    
    c = (f - 32) * 5 / 9;
    
    return c;
}

void display_result(float f, float c)
{
    printf("%f° Fahrenheit is %f° Celsius", f, c);
}

Try It

Copy

See Also