C Program to Find Volume and Surface Area of Cone

This is a C Program to find the volume and surface area of cone.

Problem Description

This C Program calculates the volume and surface area of cone.

Problem Solution

This program is used to find the the volume and surface area of cone. The formula used in this program are Surface_area = Pi * r * (r + sqrt(r2 + h2)), Volume = 1 / 3 * Pi * r2 * h where r is the radius and h is the height of the cone & Pi = 22/7.

Program/Source Code

Here is source code of the C Program to Find the volume and surface area of cone. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
 * C Program to Find the volume and surface area of cone
 */
#include <stdio.h>
#include <math.h>
 
int main()
{
 
    float radius, height;
    float surface_area, volume;
 
    printf("Enter value of radius and height of a cone :\n ");
    scanf("%f%f", &radius, &height);
    surface_area = (22 / 7) * radius * (radius + sqrt(radius * radius + height * height));
    volume = (1.0/3) * (22 / 7) * radius * radius * height;
    printf("Surface area of cone is: %.3f", surface_area);
    printf("\n Volume of cone is : %.3f", volume);
    return 0;
}
Program Explanation

In this C program, library function defined in <math.h> header file is used to compute mathematical functions. We are reading the ‘radius’ and ‘height’ of a cone. To find the surface area and the volume, the following formulas are used.

advertisement

Surface area = 3.14 * radius * (radius + sqrt ((radius * radius) + (height * height)),

Volume = 1 / 3 * 3.14 * radius * radius * height.

Runtime Test Cases
 
Output:
$ cc pgm31.c -lm
$ a.out
Enter value of radius and height of a cone :
 6 9
Surface area of cone is: 302.700
Volume of cone is : 324.000

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Free 30-Day Java Certification Bootcamp is Live. Join Now!

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.