C Program to Compute Volume and Surface Area of Cone

Write C Program to Compute the Volume and the Surface Area of a Cone

//Write a C Program to Compute Volume and Surface Area of Cone

#include <stdio.h>
#include <math.h>
#define PI 3.14

int main()
{

    float radius, height;
    float surface_area, volume;

    printf("Enter radius of a cone :--> ");
    scanf("%f", &radius);

    printf("Enter height of a cone :--> ");
    scanf("%f", &height);

    //cone area formula
    surface_area = PI * radius * (radius + sqrt(radius * radius + height * height));

    //cone volume formula
    volume = (1.0/3) * PI * radius * radius * height;

    printf("Surface area of cone :--> %.2f\n", surface_area);
    printf("Volume of cone :--> %.2f", volume);

    return 0;
}

Output:

Enter radius of a cone :--> 5
Enter height of a cone :--> 8

Surface area of cone :--> 226.61
Volume of cone :--> 209.33

≪ Previous | Next ≫