[URI Online Judge] – 1011 – Sphere

Make a program that calculates and print the volume of a sphere given the radius (R) of the circle. The formula to calculate the volume is: (4/3) * pi * R3. For the purposes of this problem the value of pi is 3.14159.

Tip: Use (4/3.0) or (4.0/3) in your formula, because some languages (including C++) assume that the result dividing two integers is another integer. :)


The input file contain an integer number.


The output file will contain a message like the following example. Remember the space before and after the equal signal. The value must be printed with 3 digits after the decimal point.

Sample Inputs Sample Outputs
3 VOLUME = 113.097
15 VOLUME = 14137.155
1523 VOLUME = 14797486501.627


#include <cstdio>

#define pi 3.14159

int main(){
float r;
scanf(“%f”, &r);
printf(“VOLUME = %.3f\n”, 4.0 / 3.0 * pi * (r * r * r));


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s