finding the volume of a sphere of given radius flow chart
Answers
Answer:
Got it!
This site uses cookies to deliver our services and to show you relevant ads. By using our site, you acknowledge that you have read and understood our Privacy Policy. Your use of w3resource Services, is subject to these policies More info
C Exercises: Calculates the volume of a sphere
Last update on February 26 2020 08:07:28 (UTC/GMT +8 hours)
C Input Output statement and Expressions: Exercise-2 with Solution
Write a C program that calculates the volume of a sphere.
C Programming : Volume of a sphere
A sphere is a perfectly round geometrical object in three-dimensional space that is the surface of a completely round ball.
In three dimensions, the volume inside a sphere is derived to be V = 4/3*π*r3 where r is the radius of the sphere
C Input Output: Calculate volume of a sphere
Sample Solution:
C Code:
#include <stdio.h>
float myradius; /* radius of the sphere */
float myvolume; /* volume of the sphere (to be computed) */
char line_text[50]; /* a line from the keyboard */
/* the value of pi to 50 places, from wikipedia */
const float PI = 3.14159265358979323846264338327950288419716939937510;
int main() {
printf("Input the radius of the sphere : ");
fgets(line_text, sizeof(line_text), stdin);
sscanf(line_text, "%f", &myradius);
myvolume = (4.0 / 3.0) * PI * (myradius * myradius * myradius); /* volumn=(4/3) * pi * r^3*/
printf("The volume of sphere is %f.\n", myvolume);
return(0);
}
Sample Output:
Input the radius of the sphere : 2.56
The volume of sphere is 70.276237.
Flowchart:
C Programming Input Output Flowchart: Calculate the volume of a sphere.
C Programming Code Editor:
Improve this sample solution and post your code through Disqus.