Dado el número N , la tarea es encontrar la raíz cúbica usando la función de registro.
Ejemplos:
Entrada: N = 8
Salida: 2.000000
Entrada: N = 27
Salida: 3.000000
Planteamiento: Para resolver el problema mencionado anteriormente utilizaremos la función log(), según la siguiente fórmula:
Sea d la raíz cúbica de N.
=> ∛N = d
=> N (1/3) = d
Ahora, aplica log en ambos lados:
log 3 (N (1/3) ) = log 3 (d)
=> log 3 (d) = 1/ 3 * log 3 (N)
=> d = 3 (1/3 * log 3 (N))
A continuación se muestra la implementación del problema anterior:
C++
// C++ program to Find Cube root // of a number using Logarithm #include <bits/stdc++.h> // Function to find the cube root double cubeRoot(double n) { // calculate the cube root double ans = pow(3, (1.0 / 3) * (log(n) / log(3))); // Return the final answer return ans; } // Driver code int main() { double N = 8; printf("%.2lf ", cubeRoot(N)); return 0; }
Java
// Java program to Find Cube root // of a number using Logarithm class GFG{ // Function to find the cube root static double cubeRoot(double n) { // Calculate the cube root double ans = Math.pow(3, ((1.0 / 3) * (Math.log(n) / Math.log(3)))); // Return the final answer return ans; } // Driver code public static void main(String[] args) { double N = 8; System.out.printf("%.2f", cubeRoot(N)); } } // This code is contributed by Rajput-Ji
Python3
# Python3 program to find cube root # of a number using logarithm import numpy as np # Function to find the cube root def cubeRoot(n): # Calculate the cube root ans = pow(3, (1.0 / 3) * (np.log(n) / np.log(3))) # Return the final answer return ans # Driver code N = 8 print("%.2f" % cubeRoot(N)) # This code is contributed by PratikBasu
C#
// C# program to find cube root // of a number using logarithm using System; class GFG{ // Function to find the cube root static double cubeRoot(double n) { // Calculate the cube root double ans = Math.Pow(3, ((1.0 / 3) * (Math.Log(n) / Math.Log(3)))); // Return the readonly answer return ans; } // Driver code public static void Main(String[] args) { double N = 8; Console.Write("{0:F2}", cubeRoot(N)); } } // This code is contributed by sapnasingh4991
Javascript
<script> // javascript program to Find Cube root // of a number using Logarithm // Function to find the cube root function cubeRoot( n) { // calculate the cube root let ans = Math.pow(3, (1.0 / 3) * (Math.log(n) / Math.log(3))); // Return the final answer return ans; } // Driver code let N = 8; document.write( cubeRoot(N).toFixed(2)); // This code is contributed by todaysgaurav </script>
Producción:
2.00