A serious problem lies in the Compute volume function. Additionally, the program
ID: 3807800 • Letter: A
Question
A serious problem lies in the Compute volume function. Additionally, the programmer was confused about parameters and local variables. Make this function work correctly, and also improve its use of parameters, changing main as necessary. # include # define Pi E 3.14 float Compute Volume (float r, float h, float ans, float r2); int main () { float radius, height, ans, r2 printf ("radius :"); scant ("%g", &radius;): printf ("Height : "); scant("% g" &height;): ans = Compute Volume (radius, height, ans, r2); printf ("Volume:%g/n", ans); return (); } float Compute Volume (float r, float h, float ans, float r2) { r2 = r*r; ans = (1/3) * PIE * r2*h; return ans; }Explanation / Answer
#include <stdio.h>
#define PIE 3.14
float ComputeVolme(float r, float h) ;
int main()
{
float radius, height, ans;
printf("Radius: ");
scanf("%f", &radius);
printf("Height: ");
scanf("%f", &height);
ans = ComputeVolme(radius, height);
printf("Volumn: %g ", ans);
return 0;
}
float ComputeVolme(float r, float h) {
return (PIE * r * r * h)/3;
}
Output:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Radius: 3.3
Height: 4.4
Volumn: 50.1521
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.