Return

Temperature conversion.

Write a program  that converts a temperature from Celsius into Fahrenheit.

#include <stdio.h>


double tempF(double tempc){
 double conv = (9*tempc)/5 +32;
 return conv;
 }


int main(void) {
 
 double tempC;

printf("Enter temperature in Celsius:\n");
 scanf("%lf", &tempC);

printf("Fahrenheit: %.2lf\n", tempF(tempC));

return 0;
}

Function call in expression.

Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call FindMax() twice in an expression.

#include <stdio.h>

double FindMax(double num1, double num2) {
 double maxVal;

// Note: if-else statements need not be understood to complete this activity
 if (num1 > num2) { // if num1 is greater than num2,
 maxVal = num1; // then num1 is the maxVal.
 }
 else { // Otherwise,
 maxVal = num2; // num2 is the maxVal.
 }
 return maxVal;
}

int main(void) {
 double numA = 5.0;
 double numB = 10.0;
 double numY = 3.0;
 double numZ = 7.0;
 double maxSum = 0.0;

maxSum = FindMax(numA, numB) + FindMax(numY, numZ);

printf("maxSum is: %.1f\n", maxSum);

return 0;
}

Function definition: Volume of a pyramid.

Define a function PyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations:
Volume = base area x height x 1/3
Base area = base length x base width.
(Watch out for integer division).

#include <stdio.h>

double PyramidVolume(double baseLength, double baseWidth, double pyramidHeight){
 double baseArea;
 double volume;
 
baseArea = baseLength * baseWidth;
volume = (baseArea * pyramidHeight)/3;

return volume;
 }

int main(void) {
 printf("Volume for 1.0, 1.0, 1.0 is: %f\n", PyramidVolume(1.0, 1.0, 1.0) );
 return 0;
}