给定一个长方体和三个整数L , B和H。如果长方体的长度增加L% ,则宽度增加B%,而高度增加H% 。任务是找到长方体体积的百分比增加。
例子:
Input: L = 50, B = 20, H = 10
Output: 98%
Input: L = 10, B = 20, H = 30
Output: 71.6%
方法:假设长方体的原始长度,宽度和高度分别为l , b和h 。现在,增加的长度将是(l +((L * l)/ 100)),即,增加的长度= l *(1 +(L / 100)) 。类似地,增加的宽度和高度将增加Beadth = b *(1 +(B / 100)),而增加的Height = h *(1 +(H / 100)) 。
现在,计算originalVol = l * b * h,并增加volumeVolume =增加长度*增加宽度*增加高度。
并且,增加的百分比可以找到为((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
下面是上述方法的实现:
C++
// C++ implementation of the approach
#include
using namespace std;
// Function to return the percentage increase
// in the volume of the cuboid
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;
}
// Driver code
int main()
{
double l = 50, b = 20, h = 10;
cout << increaseInVol(l, b, h) << "%";
return 0;
}
Java
// Java implementation of the approach
class GFG
{
// Function to return the percentage increase
// in the volume of the cuboid
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;
}
// Driver code
public static void main(String[] args)
{
double l = 50, b = 20, h = 10;
System.out.println(increaseInVol(l, b, h) + "%");
}
}
// This code is contributed by Code_Mech
Python3
# Python3 implementation of the approach
# Function to return the percentage increase
# in the volume of the cuboid
def increaseInVol(l, b, h):
percentInc = ((1 + (l / 100)) *
(1 + (b / 100)) *
(1 + (h / 100)))
percentInc -= 1
percentInc *= 100
return percentInc
# Driver code
l = 50
b = 20
h = 10
print(increaseInVol(l, b, h), "%")
# This code is contributed by Mohit Kumar
C#
// C# implementation of the approach
using System;
class GFG
{
// Function to return the percentage increase
// in the volume of the cuboid
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;
}
// Driver code
public static void Main()
{
double l = 50, b = 20, h = 10;
Console.WriteLine(increaseInVol(l, b, h) + "%");
}
}
// This code is contributed by Code_Mech
98%