Task1: Write a C program that computes the surface area and volume of a cone in
ID: 3739286 • Letter: T
Question
Task1: Write a C program that computes the surface area and volume of a cone in square cm and cubic cm respectively. The program has the main function and two other functions getInput and computeResults. The getlnput function is used to prompt for and read the radius r and the length L of the slant side of the cone both in cm, it then returns these two values. The computeResults function receives the radius r and the length L of the slant side of the cone, it then returms the surface area and the volume of the cone Hint: IT hon Note: Your program must define a constant with a value of 3.141592 . The computeResults function must not contain scanf or printf statements; the printing of the results must be in the main function » The main function must display an appropriate error message and terminate if the input is invalid.Explanation / Answer
#include <stdio.h>
#include <math.h>
int main()
{
float radius, height, length;
float surface_area, volume;
getInput(&radius , &length);
computeResults(radius, length, &height, &surface_area, &volume);
printf("Surface area of cone is: %.3f", surface_area);
printf(" Volume of cone is : %.3f", volume);
return 0;
}
float computeResults(float radius, float length, float* height, float* surface_area , float* volume)
{
const float pi = 3.141592;
*height = sqrt((length * length) - (radius * radius)
*surface_area = pi * radius * (radius + sqrt(radius * radius + height * height));
*volume = (1.0/3) * pi * radius * radius * height;
}
void getInput(float* radius , float* length)
{
printf("Enter value of radius and length of a cone : ");
scanf("%f%f", &radius, &length);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.