Program to calculate Volume and Surface Area of Sphere

Description

To calculate volume of a Sphere use formula
	Volume = 4/3 x PI x radius x radius x radius

To calculate Surface Area of a Cylinder use formula
	Surface Area = 4 x PI x radius x radius
	
	where PI = 3.14285714286

C/C++

/* C Program to calculate Volume and Surface Area of Sphere */
//Save it as VolumeSurfaceAreaSphere.c

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

int main(){

    float radius, volume, surfaceArea;

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


    //The volume of sphere is calculated using the formula
    //Volume = 4/3 x PI x radius x radius x radius
    volume = ((float)4/3) * PI * pow(radius,3);

    printf("The volume of sphere : %f",volume);

    
    //The Surface area of sphere is calculated using the formula
    //Surafce Area = 4 x PI x radius x radius
    surfaceArea = 4 * PI * pow(radius,2);

    printf("\nThe Surface Area of sphere : %.3f",surfaceArea);

    return 0;
}
Input:
Enter the Radius of Sphere : 2

Output:
The volume of sphere : 33.52381
The Surface Area of sphere : 50.285713

Java

/* Java Program to calculate Volume and Surface Area of Sphere */
//Save it as VolumeSurfaceAreaSphere.java

import java.io.*;
import java.util.Scanner;

public class VolumeSurfaceAreaSphere {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        
        float radius, volume, surfaceArea, PI=(float) 3.14285714286;

        System.out.println("Enter the Radius of Sphere : ");
        radius = scanner.nextFloat();

        
        //The volume of sphere is calculated using the formula
        //Volume = 4/3 x PI x radius x radius x radius
        volume = (float) (((float)4/3) * PI * Math.pow(radius,3));

        System.out.println("The volume of sphere : "+volume);
        
        
        //The Surface area of sphere is calculated using the formula
        //Surafce Area = 4 x PI x radius x radius
        surfaceArea = (float) (4 * PI * Math.pow(radius,2));

        System.out.println("The Surface Area of sphere : "+surfaceArea);
    }
}
Input:
Enter the Radius of Sphere : 
2

Output:
The volume of sphere : 33.52381
The Surface Area of sphere : 50.285713

Related Programs

1) Program to calculate area of a circle
2) Program to calculate area of triangle
3) Program to calculate Area Of Right angle triangle
4) Program to calculate area of square
5) Program to calculate area of a Rectangle
6) Program to calculate volume and surface area of cube
7) Program to calculate volume and surface area of cylinder
Share Me

Leave a Reply