C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Surface Area of a Sphere

Introduction

A sphere is a perfectly round 3D solid object where every point on the surface is equidistant from the center.
Examples in real life include balls, bubbles, and planets.

The surface area of a sphere is the total area covering its outer surface.
The formula is:

Surface Area=4πr2

where

  • r = radius of the sphere
  • π (pi) ≈ 3.14159

 

C Program: Surface Area of a Sphere

C

#include <stdio.h>

#define PI 3.14159   // Define constant PI

 

int main() {

    float radius, surface_area;

 

    // Input radius

    printf("Enter the radius of the sphere: ");

    scanf("%f", &radius);

 

    // Calculate surface area

    surface_area = 4 * PI * radius * radius;

 

    // Display result

    printf("Surface Area of Sphere = %.2f\n", surface_area);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the radius of the sphere: 7
Surface Area of Sphere = 615.75

OUTPUT 2 :
Enter the radius of the sphere: 3.5
Surface Area of Sphere = 153.94

Explanation

  1. The program asks for the radius of the sphere.
  2. Formula applied: 4 × π × r².
  3. PI is defined with #define for accuracy.
  4. The result is printed with two decimal places.