Program to Compute Volume and Surface Area of a Cuboid
- Write a program to Compute Volume and Surface Area of a Cuboid in C
- Write a program to Compute Volume and Surface Area of a Cuboid in C++
- Write a program to Compute Volume and Surface Area of a Cuboid in Python
- Write a program to Compute Volume and Surface Area of a Cuboid in PHP
- Write a program to Compute Volume and Surface Area of a Cuboid in Java
- Write a program to Compute Volume and Surface Area of a Cuboid in Java Script
- Write a program to Compute Volume and Surface Area of a Cuboid in C#
Explanation:
A cuboid is a three-dimensional geometric shape with six rectangular faces, where opposite faces are equal and parallel.
Formulas:
Volume (V): Volume = Length x Width x Height
Surface Area (SA): Surface Area = 2 × (Length x Width + Width x Height + Height x Lenght)
Program to Compute Volume and Surface Area of a Cuboid
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h>
int main() {
float length, width, height, volume, surfaceArea;
printf("Enter the length of the cuboid: ");
scanf("%f", &length);
printf("Enter the width of the cuboid: ");
scanf("%f", &width);
printf("Enter the height of the cuboid: ");
scanf("%f", &height);
volume = length * width * height;
surfaceArea = 2 * (length * width + width * height + length * height);
printf("Volume: %.2f\n", volume);
printf("Surface Area: %.2f\n", surfaceArea);
return 0;
}
#include <iostream>
using namespace std;
int main() {
float length, width, height, volume, surfaceArea;
cout << "Enter the length of the cuboid: ";
cin >> length;
cout << "Enter the width of the cuboid: ";
cin >> width;
cout << "Enter the height of the cuboid: ";
cin >> height;
volume = length * width * height;
surfaceArea = 2 * (length * width + width * height + length * height);
cout << "Volume: " << volume << endl;
cout << "Surface Area: " << surfaceArea << endl;
return 0;
}
length = float(input("Enter the length of the cuboid: "))
width = float(input("Enter the width of the cuboid: "))
height = float(input("Enter the height of the cuboid: "))
volume = length * width * height
surface_area = 2 * (length * width + width * height + length * height)
print(f"Volume: {volume}")
print(f"Surface Area: {surface_area}")
<?php
$length = (float)readline("Enter the length of the cuboid: ");
$width = (float)readline("Enter the width of the cuboid: ");
$height = (float)readline("Enter the height of the cuboid: ");
$volume = $length * $width * $height;
$surfaceArea = 2 * ($length * $width + $width * $height + $length * $height);
echo "Volume: $volume\n";
echo "Surface Area: $surfaceArea\n";
?>
import java.util.Scanner;
public class Cuboid {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length of the cuboid: ");
float length = sc.nextFloat();
System.out.print("Enter the width of the cuboid: ");
float width = sc.nextFloat();
System.out.print("Enter the height of the cuboid: ");
float height = sc.nextFloat();
float volume = length * width * height;
float surfaceArea = 2 * (length * width + width * height + length * height);
System.out.println("Volume: " + volume);
System.out.println("Surface Area: " + surfaceArea);
}
}
const length = parseFloat(prompt("Enter the length of the cuboid: "));
const width = parseFloat(prompt("Enter the width of the cuboid: "));
const height = parseFloat(prompt("Enter the height of the cuboid: "));
const volume = length * width * height;
const surfaceArea = 2 * (length * width + width * height + length * height);
console.log(`Volume: ${volume}`);
console.log(`Surface Area: ${surfaceArea}`);
using System;
class Program {
static void Main() {
Console.Write("Enter the length of the cuboid: ");
float length = float.Parse(Console.ReadLine());
Console.Write("Enter the width of the cuboid: ");
float width = float.Parse(Console.ReadLine());
Console.Write("Enter the height of the cuboid: ");
float height = float.Parse(Console.ReadLine());
float volume = length * width * height;
float surfaceArea = 2 * (length * width + width * height + length * height);
Console.WriteLine("Volume: " + volume);
Console.WriteLine("Surface Area: " + surfaceArea);
}
}