Percentage increase in the volume of cuboid if length, breadth and height are increased by fixed percentages
Last Updated :
25 Mar, 2022
Given a cuboid and three integers L, B, and H. If the length of the cuboid is increased by L%, breadth is increased by B% percent, and height is increased by H% percent. The task is to find the percentage increase in the volume of the cuboid.
Examples:
Input: L = 50, B = 20, H = 10
Output: 98%
Input: L = 10, B = 20, H = 30
Output: 71.6%
Approach: Suppose the original length, breadth and height of the cuboid be l, b and h respectively. Now, the increased length will be (l + ((L * l) / 100)) i.e. increasedLength = l * (1 + (L / 100)). Similarly, increased breadth and height will be increasedBreadth = b * (1 + (B / 100)) and increasedHeight = h * (1 + (H / 100)).
Now, calculate originalVol = l * b * h and increasedVol = increasedLength * increasedBreadth * increasedHeight.
And, the percentage increase can be found as ((increasedVol – originalVol) / originalVol) * 100
(((l * (1 + (L / 100)) * b * (1 + (B / 100)) h * (1 + (H / 100))) – (l * b * h)) / (l * b * h)) * 100
((l * b * h * (((1 + (L / 100)) * (1 + (B / 100)) * (H / 100)) – 1)) / (l * b * h)) * 100
(((1 + (L / 100)) * (1 + (B / 100)) * (1 + (H / 100))) – 1) * 100
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
double increaseInVol( double l, double b, double h)
{
double percentInc = (1 + (l / 100))
* (1 + (b / 100))
* (1 + (h / 100));
percentInc -= 1;
percentInc *= 100;
return percentInc;
}
int main()
{
double l = 50, b = 20, h = 10;
cout << increaseInVol(l, b, h) << "%" ;
return 0;
}
|
Java
class GFG
{
static double increaseInVol( double l,
double b,
double h)
{
double percentInc = ( 1 + (l / 100 )) *
( 1 + (b / 100 )) *
( 1 + (h / 100 ));
percentInc -= 1 ;
percentInc *= 100 ;
return percentInc;
}
public static void main(String[] args)
{
double l = 50 , b = 20 , h = 10 ;
System.out.println(increaseInVol(l, b, h) + "%" );
}
}
|
Python3
def increaseInVol(l, b, h):
percentInc = (( 1 + (l / 100 )) *
( 1 + (b / 100 )) *
( 1 + (h / 100 )))
percentInc - = 1
percentInc * = 100
return percentInc
l = 50
b = 20
h = 10
print (increaseInVol(l, b, h), "%" )
|
C#
using System;
class GFG
{
static double increaseInVol( double l,
double b,
double h)
{
double percentInc = (1 + (l / 100)) *
(1 + (b / 100)) *
(1 + (h / 100));
percentInc -= 1;
percentInc *= 100;
return percentInc;
}
public static void Main()
{
double l = 50, b = 20, h = 10;
Console.WriteLine(increaseInVol(l, b, h) + "%" );
}
}
|
Javascript
<script>
function increaseInVol(l, b, h)
{
let percentInc = (1 + (l / 100))
* (1 + (b / 100))
* (1 + (h / 100));
percentInc -= 1;
percentInc *= 100;
return percentInc;
}
let l = 50, b = 20, h = 10;
document.write(increaseInVol(l, b, h) + "%" );
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...