Hamza Azam Hamza Azam - 2 months ago 7
C Question

Write a program that prompts the user for the radius of a sphere and prints its volume

Im not getting correct answer with the following code below. Can anyone debug this code?
When I input radius = 5, the answer I get is 500.000000 whereas the original answer should be 523.80952. Can anyone please explain what's wrong here?

Sphere volume formula =4/3(π x r^3)

#include <stdio.h>

int main()


{
float radius = 0;
float volume;
float pie = 0;

printf("Enter radius");
scanf("%f", &radius);

pie = 22 / 7;

volume = (4*pie*radius*radius*radius)/3;
printf("the volume is %f", volume);

return 0;
}

Answer

You can also write pie = 3.14 ; instead of pie = 22 / 7 ;.