In this tutorial you will learn about the C Program to Find Volume and Surface Area of Sphere and its application with practical example.
C Program to Find Volume and Surface Area of a Sphere
In this tutorial, we will learn to create a C program that will Find the Volume and Surface Area of a Sphere in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C programming.
What is a Sphere?
The sphere is a ball-like geometrical 3d shape which is having a diameter equal in all positions going through the center.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input radius of the sphere from the user. 3. <strong>C</strong><strong>alculating the Surface Area and volume of a sphere </strong>using the code. 4. Printing the surface area and the volume of the sphere . 5. End the program. |
Program description:-
In this tutorial, we will create a program, that will find the Volume and Surface Area of the sphere. we will First, take the radius of the sphere as input from the user. Then we will calculate the surface area and the volume of a sphere using arithmetic expressions. At last, we will print the Volume and Surface Area of a sphere.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* C Program to find Volume and Surface Area of Sphere */ #include <stdio.h>//including the header file #define PI 3.14//defining the value of PI int main()//main function body { //defining the required variabled for the program. float rad, sa,vol; //rad = it will hold the radius of the sphere //sa = it will hold the Surface area of the sphere //vol = it will hold the Volume of the sphere //Taking the radius as input from the user. printf("\n Please Enter the radius of a Sphere \n"); scanf("%f", &rad);//Scanning the radius from the user //calculating the surface area of the sphere sa = 4 * PI * rad * rad; //calculating the volume of the sphere vol = (4.0 / 3) * PI * rad * rad * rad; //prining the surface area of the sphere printf("\n The Surface area of a Sphere = %.2f", sa); //prining the Volume of the sphere printf("\n The Volume of a Sphere = %.2f", vol); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- rad = it will hold the integer value for the input radius of the sphere.
- sa = it will hold the integer the surface area of the sphere
- vol = it will hold the value of the volume of the sphere.
Taking the input radius of the sphere.
Calculating the surface area & volume of the sphere.
Printing the volume and surface area of the sphere.