C Program to Find Volume and Surface Area of Cone

This C program calculates the volume and surface area of a cone based on the provided radius and height.

Problem statement

Given the radius and height of a cone, the program calculates its volume and surface area.

The program follows the steps below:

  1. It prompts the user to enter the radius and height of the cone.
  2. The program calculates the slant height of the cone using the Pythagorean theorem.
  3. Using the provided inputs and calculated slant height, the program computes the volume and surface area of the cone.
  4. Finally, it displays the calculated volume and surface area on the screen.

C Program to Find Volume and Surface Area of Cone

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

int main()
{
    float radius, height;
    float volume, surface_area;
    float slant_height;

    printf("***** Cone Volume and Surface Area Calculator *****\n\n");

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

    // Calculate the slant height
    slant_height = sqrt(pow(radius, 2) + pow(height, 2));

    // Calculate the volume of the cone
    volume = (1.0 / 3.0) * M_PI * pow(radius, 2) * height;

    // Calculate the surface area of the cone
    surface_area = M_PI * radius * (radius + slant_height);

    printf("\nVolume of the cone: %.2f cubic units\n", volume);
    printf("Surface area of the cone: %.2f square units\n", surface_area);

    return 0;
}

How it works

  1. The program prompts the user to enter the radius and height of the cone.
  2. The program calculates the slant height of the cone using the formula sqrt(radius^2 + height^2).
  3. Using the provided inputs and calculated slant height, the program calculates the volume using the formula (1/3) * π * radius^2 * height and the surface area using the formula π * radius * (radius + slant_height).
  4. The calculated volume and surface area are displayed on the screen

Input / output

C Program to Find Volume and Surface Area of Cone

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...
This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...
This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...