In this tutorial you will learn about the C Program to Find Volume and Surface Area of a Cone and its application with practical example.
C Program to Find Volume and Surface Area of a Cone
In this tutorial, we will learn to create a C program that will Find the Volume and Surface Area of a Cone 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.
- Mathematical operations in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input radius and height from the user for the cone. 3. <strong>C</strong><strong>alculating the surface Area and volume of cone</strong> using the code. 4. Printing the area of the circle. 5. End the program. |
Program description:-
In today’s tutorial, we will create a program, that will calculate the Volume and Surface Area of a Cone using C programming. First, take the input radius and the height of the cone from the user. Then we will find the surface Area and the volume of a cone using the mathematical functions and calculations in the c programming language. At last, we will print the Volume and Surface Area of a cone.
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 30 31 32 33 34 35 36 37 38 |
/* C Program to find Volume and Surface Area of a Cone */ //including the header files of the program. #include <stdio.h> #include <math.h> int main() { //declaring the required variables for the program. float rd, ht; float vm, SA, l, LSA; //rd = it will hold the input radius from the user. //ht = it will hold the input height from the user. //vm = it will hold the volume of the cone. //taking the input radius and the height of the cone. printf("\n Please Enter Radius and Height of a Cone\n"); scanf("%f %f", &rd, &ht);//Scannig the radius and height of the cone. //Calculating the slant of the code. l = sqrt(rd * rd + ht * ht); //Calculating the Surface Area of a Cone SA = M_PI * rd * (rd + l); //Calculating the Volume of a Cone vm = (1.0/3) * M_PI * rd * rd * ht; //Calculating the Lateral Surface Area of a Cone LSA = M_PI * rd * l; //printing the slant of the cone printf("\n Length of a Side (Slant)of a Cone = %.2f", l); //printing the Surface Area of a Cone printf("\n Surface Area of a Cone = %.2f", SA); //printing the Volume of a Cone printf("\n Volume of a Cone = %.2f", vm); //printing the Lateral Surface Area of a Cone printf("\n Lateral Surface Area of a Cone = %.2f", LSA); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- rd = it will hold the integer value for the input radius of the cone.
- ht = it will hold the integer value for the input height of the cone.
- vm = it will hold the value of the volume of the cone.
Taking Input the radius and height of the cone from the user.
Calculating the surface area & volume of the cone.
Printing the volume and surface area of the cone.