Program to Calculate the surface area and volume of a Cuboid

Problem statement:-  Program to Calculate the surface area and volume of a Cuboid.

Formula:

Surface Area Of Cuboid(A):  2(lw+lh+hw)

Volume of Cuboid(V): l×w×h

where l=Length of the Cuboid 
           w=Width of the Cuboid
           h=Height of the Cuboid

Data requirement:-

   Input Data:- l,w,h

  Output Data:- surface_area, volume

Program in C

Here is the source code of the C Program to Calculate the surface area and volume of a Cuboid.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    printf("Enter the length of the cuboid:");
    int l;
    scanf("%d",&l);
    printf("Enter the height of the cuboid:");
    int h;
    scanf("%d",&h);
    printf("Enter the weight of the cuboid:");
    int w;
    scanf("%d",&w);

    double surface_area=2*((l*w)+(l*h)+(h*w));
    double volume=l*w*h;
    printf("Surface Area of the cuboid = %0.2lf\n",surface_area);
    printf("Volume of the cuboid = %0.2lf",volume);
}

Input/Output:
Enter the length of the cuboid:4
Enter the height of the cuboid:5
Enter the weight of the cuboid:7
Surface Area of the cuboid = 166.00
Volume of the cuboid = 140.00

Program in C++

Here is the source code of the C++ Program to Calculate the surface area and volume of a Cuboid.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    cout<<"Enter the length of the cuboid:";
    int l;
    cin>>l;
    cout<<"Enter the height of the cuboid:";
    int h;
    cin>>h;
    cout<<"Enter the weight of the cuboid:";
    int w;
    cin>>w;

    double surface_area=2*((l*w)+(l*h)+(h*w));
    double volume=l*w*h;
    cout<<"Surface Area of the cuboid = "<<surface_area;
    cout<<"\nVolume of the cuboid = "<<volume;
}

Input/Output:
Enter the length of the cuboid:10
Enter the height of the cuboid:12
Enter the weight of the cuboid:15
Surface Area of the cuboid = 900
Volume of the cuboid = 1800

Program in Java
  
Here is the source code of the Java Program to Calculate the surface area and volume of a Cuboid.

Code:

import java.util.Scanner;
public class SurfaceAreaAndVolumeOfCuboid {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the length of the cuboid:");
    int l=cs.nextInt();
    System.out.println("Enter the height of the cuboid:");
    int h=cs.nextInt();
    System.out.println("Enter the weight of the cuboid:");
    int w=cs.nextInt();
    double surface_area=2*((l*w)+(l*h)+(h*w));
    double volume=l*w*h;
    System.out.println("Surface Area of the cuboid = "+surface_area);
    System.out.println("Volume of the cuboid = "+volume);
     cs.close();
}
}

Input/Output:
Enter the length of the cuboid:
15
Enter the height of the cuboid:
16
Enter the weight of the cuboid:
20
Surface Area of the cuboid = 1720.0
Volume of the cuboid = 4800.0

Program in Python
  
Here is the source code of the Python Program to Calculate the surface area and volume of a Cuboid.

Code:

l=int(input("Enter the length of the cuboid:"))
h=int(input("Enter the height of the cuboid:"))
w=int(input("Enter the weight of the cuboid:"))
surface_area=2*((l*w)+(l*h)+(h*w))
volume=l*w*h
print("Surface Area of the cuboid = ",surface_area)
print("Volume of the cuboid = ",volume)

Input/Output:

Post a Comment

1 Comments

Please do not Enter any spam link in the comment box