Program to calculate volume and surface area of cube

Description

To calculate volume of a Cube use formula
    volume = side x side x side

To calculate Surface Area of a Cube use formula
    Surface Area = 6 x side x side

C/C++

/* C Program to calculate volume and surface area of cube */
//Save it as VolumeSurfaceAreaCube.c

#include<stdio.h>
int main(){

    float side, volume, surfaceArea;

    printf("Enter the side of a cube : ");
    scanf("%f",&side);

    volume = (side * side * side);

    surfaceArea = (6 * side * side);

    printf("The volume of cube : %.3f",volume);
    printf("\nThe surface area of cube : %.3f",surfaceArea);

    return 0;
}
Input:
Enter the side of a cube : 2

Output:
The volume of cube : 8.0
The surface area of cube : 24.0

Java

/* Java Program to calculate volume and surface area of cube */
//Save it as VolumeSurfaceAreaCube.java

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

public class VolumeSurfaceAreaCube {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
        
            float side, volume, surfaceArea;

        System.out.println("Enter the side of a cube : ");
        side = scanner.nextFloat();

        volume = (side * side * side);

        surfaceArea = (6 * side * side);

        System.out.println("The volume of cube : " + volume);
        System.out.println("The surface area of cube : " + surfaceArea);
    }
}
Input:
Enter the side of a cube : 
2

Output:
The volume of cube : 8.0
The surface area of cube : 24.0

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 cylinder
7) Program to calculate Volume and Surface Area of Sphere
8) Check whether a given number is a perfect number or not
9) Program to Check Whether a Number is Prime or Not
10) Program to Check Whether a Character is a Vowel or Not
Share Me

Leave a Reply