C Tutorial
This c program is used to compute the volume of a sphere based on the user inputs radius.
Volume of a sphere = (4/3) × π × r3
here pi denotes Greek letter π and value is around 3.14
// Finds volume of a sphere #include<stdio.h> void main() { int radius; float volume=0, pi=3.14; printf("\nFinds volume of a sphere\n-------------------"); printf("\nEnter radius: "); scanf("%d", &radius); volume = ((float)4/(float)3)*pi*(radius*radius*radius); printf("Volume of a sphere is: %.2f", volume); }
Output:
$ cc volume-of-sphere.c $ ./a.out Finds volume of a sphere ------------------- Enter radius: 8 Volume of a sphere is: 2143.57
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page