×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to calculate the surface area, volume of the Sphere

Here, we are going to learn how to calculate the surface area, volume of the Sphere using C program?
Submitted by Nidhi, on August 10, 2021

Problem statement

Read the radius of Sphere from the user, and then calculate the surface area and volume of the Sphere.

Surface area of the Sphere:

The formula to calculate the surface area of the Sphere is:

surface area of the Sphere

Volume of the Sphere:

The formula to calculate the volume of the Sphere is:

volume of the Sphere

C program to calculate the surface area, volume of the Sphere

The source code to calculate the surface area, volume of the Sphere is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to calculate the surface Area and
// volume of Sphere

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

int main()
{
    float radius = 0;

    float volume = 0;
    float area = 0;

    printf("Enter the radius: ");
    scanf("%f", &radius);

    volume = (4.0 / 3) * (3.14) * pow(radius, 3);
    area = 4 * (3.14) * pow(radius, 2);

    printf("Volume of Sphere 	  : %f\n", volume);
    printf("Surface area of Sphere: %f\n", area);

    return 0;
}

Output

RUN 1:
Enter the radius: 2.45
Volume of Sphere          : 61.569649
Surface area of Sphere: 75.391403

RUN 2:
Enter the radius: 1.0
Volume of Sphere          : 4.186666
Surface area of Sphere: 12.560000

RUN 3:
Enter the radius: 110
Volume of Sphere          : 5572453.500000
Surface area of Sphere: 151976.000000

Explanation

Here, we read the value of radius from the user. Then we calculated the surface area and volume of the Sphere using standard formulas.

C Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.