User-defined functions

Basic function call.

Complete the function definition to output the hours given minutes. Output for sample program:

3.500000

Solution

#include <stdio.h>

void OutputMinutesAsHours(double origMinutes) {

double hour = origMinutes / 60;
printf("%lf", hour);

}

int main(void) {

OutputMinutesAsHours(210.0); // Will be run with 210.0, 3600.0, and 0.0.
 printf("\n");

return 0;
}

Function call with parameter: Printing formatted measurement.

Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ‘ and ” shorthand. Ex: PrintFeetInchShort(5, 8) prints:

5' 8"

Hint: Use \” to print a double quote.

#include <stdio.h>


void PrintFeetInchShort(int numFeet, int numInches){


printf("%d' %d\"", numFeet, numInches);

}


int main(void) {
 PrintFeetInchShort(5, 8); // Will be run with (5, 8), then (4, 11)
 printf("\n");

return 0;
}