C Program to Find Volume and Surface Area of Sphere

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

Problem Description

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

Problem Solution

The formula used in this program are Surface_area = 4 * Pi * r2, Volume = 4/3 * Pi * r3 where r is the radius of the sphere, Pi= 22/7

Program/Source Code

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

/*
 * C Program to Find Volume and Surface Area of Sphere
 */
 #include <stdio.h>
#include <math.h>
 
int main()
{
 
    float radius;
    float surface_area, volume;
 
    printf("Enter radius of the sphere : \n");
    scanf("%f", &radius);
    surface_area =  4 * (22/7) * radius * radius;
    volume = (4.0/3) * (22/7) * radius * radius * radius;
    printf("Surface area of sphere is: %.3f", surface_area);
    printf("\n Volume of sphere 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 ‘radius’ of the sphere. To find the surface area and volume, the following formulas are used.

advertisement
advertisement

Surface area = 4 * 3.14 * radius * radius,

Volume = 4/3 * 3.14 * radius * radius * radius.

Runtime Test Cases
 
Output:
$ cc pgm30.c
$ a.out
Enter radius of the sphere :
40
Surface area of sphere is: 19200.000
Volume of sphere is : 256000.000

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube

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
If you find any mistake above, kindly email to [email protected]

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
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.