C Program to Find Surface Area and Volume of a Cone

C Program to Find Surface Area and Volume of a Cone

C Program to Find Surface Area and Volume of a Cone

Introduction

A cone is a three-dimensional geometric shape that tapers smoothly from a flat circular base to a point called the apex. Calculating its surface area and volume is an essential concept in mathematics and engineering. This program demonstrates how to compute the surface area and volume of a cone using a C programming approach.


Formulas

To find the surface area and volume of a cone, the following formulas are used:

  • Volume: \( \frac{1}{3} \pi r^2 h \)
  • Surface Area: \( \pi r (r + l) \), where l is the slant height.
  • Slant Height: \( l = \sqrt{r^2 + h^2} \)

Here, r is the radius of the base, h is the height, and l is the slant height.


Code

#include <stdio.h>
#include <math.h>

int main() {
    float radius, height, slant_height, surface_area, volume;
    const float PI = 3.14159;

    // Input values
    printf("Enter the radius of the cone: ");
    scanf("%f", &radius);
    printf("Enter the height of the cone: ");
    scanf("%f", &height);

    // Calculations
    slant_height = sqrt((radius * radius) + (height * height));
    surface_area = PI * radius * (radius + slant_height);
    volume = (PI * radius * radius * height) / 3;

    // Output results
    printf("The slant height of the cone is: %.2f\n", slant_height);
    printf("The surface area of the cone is: %.2f\n", surface_area);
    printf("The volume of the cone is: %.2f\n", volume);

    return 0;
}
    

Output

When you run the program and provide the required inputs, the output might look like this:

Enter the radius of the cone: 3
Enter the height of the cone: 4
The slant height of the cone is: 5.00
The surface area of the cone is: 75.40
The volume of the cone is: 37.70
    

Explanation

Let's break down the steps involved in this program:

  • Input: The user provides the radius and height of the cone as inputs.
  • Calculations:
    • The slant height is calculated using the Pythagorean theorem: \( \sqrt{r^2 + h^2} \).
    • The surface area is computed using the formula \( \pi r (r + l) \).
    • The volume is determined using \( \frac{1}{3} \pi r^2 h \).
  • Output: The program displays the slant height, surface area, and volume with two decimal places for precision.

This program demonstrates how mathematical concepts can be implemented using C programming. By using formulas and basic mathematical operations, the program effectively calculates the desired properties of the cone.