Aquí se presenta un cubo, cuyo lado se incrementa en un porcentaje dado. La tarea es encontrar el aumento porcentual en el volumen del cubo.
Ejemplos:
Input: x = 10 Output: 33.1% Input: x = 50 Output: 237.5%
Acercarse
- En un cubo todos los lados son iguales, entonces
largo = ancho = alto - sea lado del cubo = a
- incremento porcentual dado = x%
- Entonces, el volumen antes del aumento = a^3
- después del aumento, nuevo lado = a + ax/100
- entonces, nuevo volumen = (a + ax/100)^3 = a^3 + (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000
- aumento de volumen = volumen nuevo – volumen antiguo = (a^3 + (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000) – a^3 = (ax/100)^3 + 3a^3x/100 + 3a^3x^2/10000
- entonces, aumento porcentual en volumen = (((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++
// 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 code int main() { double x = 10; newvol(x); return 0; }
Java
// Java program to find percentage increase // in the volume of the cube // if a side of cube is increased // by a given percentage import 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 code public static void main (String[] args) { double x = 10; newvol(x); } } // This code is contributed by anuj_67..
Python3
# 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#
// C# program to find percentage increase // in the volume of the cube // if a side of cube is increased // by a given percentage using 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 code public static void Main () { double x = 10; newvol(x); } } // This code is contributed by anuj_67..
Javascript
<script> // javascript program to find percentage increase // in the volume of the cube // if a side of cube is increased // by a given percentage function 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>
Producción:
percentage increase in the volume of the cube is 33.1%
Complejidad del tiempo: O(log(x))
Espacio Auxiliar: O(1), ya que no se ha ocupado ningún espacio extra.
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA