Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Challenge Activity 3.3.3: Function definition: Volume of a pyramid. Define a fun

ID: 3688900 • Letter: C

Question

Challenge Activity 3.3.3: 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). 1·#include 3:/* Your solution goes here 5 int main(void) t 1.0, 1.0 is: %ZF1m", PyramidVolume(1.0, 1.0, 1.0) ); for 1.0, printf("Volume return ; 6 8 108. 25.pd Run

Explanation / Answer

//PROGRAM 1
#include <stdio.h>
#include <stdlib.h>
//function to caliculat pyramid volume
double PyramidVolume(double baseLength,double baseWidth,double pyramidHeight)
{
double baseArea=baseLength*baseWidth;
double volume=baseArea*pyramidHeight*(1.0/3.0);
return volume;
}
int main()
{
printf("Volume for 1.0, 1.0, 1.0 is :%.2f ",PyramidVolume(1.0, 1.0, 1.0));
return 0;
}

OUTPUT:

Volume for 1.0, 1.0, 1.0 is :0.33

Process returned 0 (0x0) execution time : 0.029 s
Press any key to continue.

//PROGRAM 2

#include <stdio.h>
#include <stdlib.h>

int GetUserNum()
{
int num;
printf("Enter number:");
scanf("%d",&num);

return num;
}

int ComputeAvg(int num1,int num2){
return ((num1+num2)/2);
}
int main()
{
int userNum1=0;
int userNum2=0;
int avgResult=0;
userNum1=GetUserNum();
userNum2=GetUserNum();
avgResult=ComputeAvg(userNum1,userNum2);
printf("Avg:%d ",avgResult);
return 0;
}


OUTPUT:
Enter number:4
Enter number:6
Avg:5

Process returned 0 (0x0) execution time : 4.398 s
Press any key to continue.

//PROGRAM 3

#include <stdio.h>
#include <stdlib.h>


double CelsiusToKelvin(double valueCelsius)
{
double valueKelvin=0.0;
valueKelvin=valueCelsius+273.15;
return valueKelvin;
}

double KelvinToCelsius(double valueKelvin)
{
double valueCelsius=0.0;
valueCelsius=valueKelvin-273.15;
return valueCelsius;
}

int main()
{
double valueC=0.0;
double valueK=0.0;
valueC=10.0;
printf("%lf C is %lf K ",valueC,CelsiusToKelvin(valueC));
valueK=283.15;
printf("%lf K is %lf C ",valueK,KelvinToCelsius(valueK));
return 0;
}


OUTPUT:
10.000000 C is 283.150000 K
283.150000 K is 10.000000 C

Process returned 0 (0x0) execution time : 0.042 s
Press any key to continue.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote