Name

cbrt

Synopsis

Calculates the cube root of a number

#include <math.h>
doublecbrt( double x );
float cbrtf( float x );
long double cbrtl( long double x );

The cbrt() functions return the cube root of their argument x.

Example

#define KM_PER_AU (149597870.691) // An astronomical unit is the mean
                                  // distance between Earth and Sun:
                                  // about 150 million km.
#define DY_PER_YR (365.24)

double dist_au, dist_km, period_dy, period_yr;

printf( "How long is a solar year on your planet (in Earth days)?\n" );
scanf( "%lf", &period_dy );

period_yr = period_dy / DY_PER_YR;
dist_au =cbrt( period_yr * period_yr );    // by Kepler's Third Law
dist_km = dist_au * KM_PER_AU;

printf("Then your planet must be about %.0lf km from the Sun.\n", dist_km );

See Also

sqrt(), hypot(), pow()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.