cbrt() in swift
Last Updated :
03 Jan, 2024
The cbrt() function returns the cube root of a number. It is an inbuilt function in Swift. The cbrt() function in Swift returns the cube root of a number. Using the cbrt() function in Swift, we can calculate the cube root of any natural, decimal, and negative number (perfect and non-perfect cubes).
Syntax:
// return cube root of number
// number can be of any type int, float and double
// the return type is same as parameter passed
// number passed can be integer, perfect cube root or non-perfect cube root
cbrt(number)
Parameter: The parameter can be of int, float or double type.
Return value: cbrt() function returns the cube root of a number. The datatype of the return value is the same as we pass in the parameter.
Examples:
Input: 64.00
Output: 4.0
Input: 0.0
Output: 0.0
Input: 9
Output: 2.08008
Below is given program to illustrate the cbrt() function:
Swift
import Swift
import Foundation
print ( "The value of cbrt(64.00) : " , cbrt(64.00));
print ( "The value of cbrt(0.0) : " , cbrt(0.0));
print ( "The value of cbrt(10.00) : " , cbrt(10.00));
print ( "The value of cbrt(9.2) : " , cbrt(9.2));
print ( "The value of cbrt(-3.7) : " , cbrt(-3.7));
|
Output:
The value of cbrt(64.00) : 4.0
The value of cbrt(0.0) : 0.0
The value of cbrt(10.00) : 2.1544346900318834
The value of cbrt(9.2) : 2.0953791063432945
The value of cbrt(-3.7) : -1.5466803737720356...
Share your thoughts in the comments
Please Login to comment...