Volume of cuboid

Write a program to find the volume of a cuboid.

Example 1:

Input: length=5,width=3,height=4
Output: 60

Approach: Given the length, width, and height of the cuboid. 

Volume is length*width*height

Java

public class VolumeofCuboid {
    public static void main(String[] args) {
        double length = 5;
        double width = 3;
        double height = 4;
        double volume = volumeCuboid(length, width, height);
        System.out.println("Volume of cuboid is " + volume);
    }

    private static double volumeCuboid(double lengthdouble widthdouble height) {
        return length * width * height;
    }
}

C++

#include <bits/stdc++.h>
using namespace std;
//function to find the volume of
//cuboid
double volumeCuboid(double length,double width,double height)
{
    double volume=length*width*height;
    return volume;
}
int main()
{
    double length=5;
    double width=3;
    double height=4;
    double volume=volumeCuboid(length,width,height);
    cout<<"Volume of cuboid is ";
    cout<<volume<<"\n";
    return 0;
}


No comments:

Post a Comment