Program to Compute Volume and Surface Area of a Cube
- Write a program to Compute Volume and Surface Area of a Cube in C
- Write a program to Compute Volume and Surface Area of a Cube in C++
- Write a program to Compute Volume and Surface Area of a Cube in Python
- Write a program to Compute Volume and Surface Area of a Cube in PHP
- Write a program to Compute Volume and Surface Area of a Cube in Java
- Write a program to Compute Volume and Surface Area of a Cube in Java Script
- Write a program to Compute Volume and Surface Area of a Cube in C#
Explanation:
A cube is a three-dimensional shape with all sides equal in length. Each face of a cube is a square.
Formulas:
Volume (V): Volume = Side3
Where “Side” is the length of one edge of the cube.
Surface Area (SA): Surface Area = 6 × (Side2)
Since a cube has six identical square faces, the area of one face is Side2
Program to Compute Volume and Surface Area of a Cube
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { float side, volume, surfaceArea; printf("Enter the side length of the cube: "); scanf("%f", &side); volume = side * side * side; surfaceArea = 6 * side * side; printf("Volume: %.2f\n", volume); printf("Surface Area: %.2f\n", surfaceArea); return 0; }
#include <iostream> using namespace std; int main() { float side, volume, surfaceArea; cout << "Enter the side length of the cube: "; cin >> side; volume = side * side * side; surfaceArea = 6 * side * side; cout << "Volume: " << volume << endl; cout << "Surface Area: " << surfaceArea << endl; return 0; }
side = float(input("Enter the side length of the cube: ")) volume = side ** 3 surface_area = 6 * side ** 2 print(f"Volume: {volume}") print(f"Surface Area: {surface_area}")
<?php $side = (float)readline("Enter the side length of the cube: "); $volume = $side ** 3; $surfaceArea = 6 * ($side ** 2); echo "Volume: $volume\n"; echo "Surface Area: $surfaceArea\n"; ?>
import java.util.Scanner; public class Cube { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the side length of the cube: "); float side = sc.nextFloat(); float volume = side * side * side; float surfaceArea = 6 * side * side; System.out.println("Volume: " + volume); System.out.println("Surface Area: " + surfaceArea); } }
const side = parseFloat(prompt("Enter the side length of the cube: ")); const volume = Math.pow(side, 3); const surfaceArea = 6 * Math.pow(side, 2); console.log(`Volume: ${volume}`); console.log(`Surface Area: ${surfaceArea}`);
using System; class Program { static void Main() { Console.Write("Enter the side length of the cube: "); float side = float.Parse(Console.ReadLine()); float volume = side * side * side; float surfaceArea = 6 * side * side; Console.WriteLine("Volume: " + volume); Console.WriteLine("Surface Area: " + surfaceArea); } }