Percentage increase in volume of the cube if a side of cube is increased by a given percentage - GeeksforGeeks

27 Mar, 2022
Given here is a cube, whose one side is increased by a given percentage. The task is to find percentage increase in the volume of the cube.Examples:  
Input: x = 10
Output: 33.1%

Input: x = 50
Output: 237.5%
Approach  
In a cube, all sides are equal, so, length = breadth = height
let side of the cube = a
given percentage increase = x%
so, volume before increase = a^3
after increase, new side = a + ax/100
so, new volume = (a + ax/100)^3 = a^3 + (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000
increase in volume = new volume – old volume = (a^3 + (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000) – a^3 = (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000
so, percentage increase in volume = (((ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000)/a^3) * 100 = ((x/100)^3 + 3x/100 + 3x^2/10000) * 100 = x^3/10000 + 3x + 3x^2/100
Below is the implementation of the above approach:  
C++
Java
Python3
C#
Javascript
// C++ program to find percentage increase// in the volume of the cube// if a side of cube is increased// by a given percentage #include <bits/stdc++.h>using namespace std; void newvol(double x){    cout << "percentage increase "         << "in the volume of the cube is "         << pow(x, 3) / 10000 + 3 * x                + (3 * pow(x, 2)) / 100         << "%" << endl;} // Driver codeint main(){    double x = 10;    newvol(x);    return 0;}
// Java program to find percentage increase// in the volume of the cube// if a side of cube is increased// by a given percentageimport java.io.*; class GFG{ static void newvol(double x){    System.out.print( "percentage increase "    +"in the volume of the cube is "        + (Math.pow(x, 3) / 10000 + 3 * x                + (3 * Math.pow(x, 2)) / 100) );                System.out.print("%");} // Driver codepublic static void main (String[] args){    double x = 10;    newvol(x);}} // This code is contributed by anuj_67..
# Python program to find percentage increase# in the volume of the cube# if a side of cube is increased# by a given percentage def newvol(x):     print("percentage increase"            "in the volume of the cube is ",            ((x**(3)) / 10000 + 3 * x                + (3 * (x**(2))) / 100),"%"); x = 10;newvol(x); # This code is contributed by PrinciRaj1992
// C# program to find percentage increase// in the volume of the cube// if a side of cube is increased// by a given percentageusing System; class GFG{ static void newvol(double x){    Console.Write( "percentage increase "    +"in the volume of the cube is "        + (Math.Pow(x, 3) / 10000 + 3 * x                + (3 * Math.Pow(x, 2)) / 100) );                Console.Write("%");} // Driver codepublic static void Main (){    double x = 10;    newvol(x);}} // This code is contributed by anuj_67..
<script>// javascript program to find percentage increase// in the volume of the cube// if a side of cube is increased// by a given percentagefunction newvol( x){    document.write("percentage increase "         + "in the volume of the cube is "         + (Math.pow(x, 3) / 10000 + 3 * x                + (3 * Math.pow(x, 2)) / 100)         + "%" );} // Driver code    let x = 10;    newvol(x);     // This code is contributed by gauravrajput1</script>
percentage increase in the volume of the cube is 33.1%
 
Time Complexity: O(log(x))
Auxiliary Space: O(log(x))
vt_m
princiraj1992
GauravRajput1
rohitkumarsinghcna
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Convex Hull | Set 2 (Graham Scan)
Check whether a given point lies inside a triangle or not
Convex Hull using Divide and Conquer Algorithm
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7