×

Cbrt() function in C

Introduction:

The Cbrt is a function used in C programming language. The cbrt() function is a math function. Using the cbrt function, we can do the cube root of a function.

This function takes a single argument.

It is an in-built function of the C language. In the Cart() function, we give arguments or numbers, and the output is come, which is the cube root of the given arguments. 

 Syntax of the cbrt() function in C language:

Syntax means the order or arrangement in the program. The syntax is also known as the function prototype. Every function has a syntax value. The syntax of the cbrt() function is: 

 double cbrt = double (number) ;

The cbrt() function gives the cube root of a number by taking a single number or argument.

Parameters of the cbrt() function in C language:

In the cbrt() function, we use many parameters like floot, int, and long double. Cart() function is used only for the floot, and the cbrtl() function is used only for long double.

Example –

floot cbrtf (floot number); it is the use of cbrtf() function

long double cbrtl (long double number); it is the use of cbrtl() function

Returns Value of the cbrt() function in C language:

The cbrt() function only return the cube root of a number. If we give a single number, this function gives the cube root of this number. But if we give an integer of a number, then this function does not give any cube root of the integer. At this time, the function only doubles the integer value.

Input : 27
Output : 3
Input : 64
Output : 4

Header file of the cbrt() function in C language :

Every program contains some header files. For the run of any program, you must need a header file. Without a header file, you can't run any programs. So, we must produce the header file in every program.

It is a file with an extension. The cbrt() function only takes a single argument or number. 

The primary use of the header file is to propagate the declaration of code files. The cbrt() function uses as a math function. The header file of the cbrt() function in the C language is <math.h>.

It writes in the program as #include <math.h>

Mathematics :

3√x = cbrt (x) It is the use of cbrt() function in C programming language. It has done the cube root of the given number x.

What is means by Cube root?

A cube root is a number we multiply by three times to get the actual number. Example -  3√27 = 3 (when we multiply three itself by the three times like {[3*3*3] = 27}, then we get 27. So, 27 is the cube root of a number 3)

Algorithm of the cbrt() function:

The algorithm for the cbrt() function is –

Step 1: Start the program.

Step 2: Take a variable number.

Step 3: Pass the number variable to the cube root function. (cbrtf(number))

Step 4: This function returns the value. The value is only the cube root of a given number.

Step 5: Print the output.

Step 6: End the program.

Example 1

Here we given a example of the cbrt() function using C language:

//header file initialize

#include <stdio.h>
#include <math.h>
int main()
{

//value of the variable

double number = 9, cube root;
cube root = cbrt (number);

//print the output

printf(“Cube root of the number %4f = %5f” , number, cube root);
return 0;
}

Output: We compile and run the above program. The result of this above program is:

 Cube root of the number 9.0000 = 2.08008

To better understand, we give another example of the cbrt() function.

Example 2

Here we given a example of the cbrt() function using C language:

//header file initialize
#include <stdio.h>
#include <math.h>
int main()
{
float number, Cube root value;
printf(“Write any numerical value:  “);
Scanf(“%f”, & number);
Cube root value = cbrt(number);
//print the output
printf(“\n Cube root of the number %2f = %2f” , number, cube root);
return 0;
}

Output: We compile and run the above program.The result of this above program is:

Write any numerical value: 216
Cube root of the number  216.00 = 6.00

In the above two programs, we have used the cbrt() function; by the programs, we briefly discussed how to write any C language program using the cbrt() function. The cbrt() function is a mathematical function.

So we <math.h> header file in this program. We also share the output of the above two programs. The output of the two programs is the cube root of the input number or argument.


Related Topics

Dynamic memory allocation

Dynamic memory allocation is used to allocate the memory at runtime. It has following function within <stdlib.h> header file. Function Syntax malloc() malloc (number *sizeof(int)); calloc() calloc (number, sizeof(int)); realloc() realloc (pointer_name, number * sizeof(int)); free() free (pointer_name); malloc() function The process...

2 minutes read.

C Switch Statements

Switch-case statement comes under the Selection control statement; there are four types of Control statements Decision-making statements (if, if-else)Selection statements (Switch-case)Iteration statements (for, while, do-while)Jump statements (break, continue, goto) If we want...

4 minutes read.

C Program for Extended Euclidean algorithms

The Euclidean method simply computes the GCD (greatest common divisor) of two numbers, p and q. (Let's assume) The GCD of two integers is the greatest number that divides them both....

3 minutes read.

C Program to find the size of a File

Before knowing about the Program, you need to understand what the size of a file is. After that, you should know how it is going to work with the given...

4 minutes read.

What is a buffer in C?

A buffer is an area of memory set aside for the temporary storage of data. A data buffer (or just buffer) is a region of a physical memory storage used to...

5 minutes read.

Different ways to Declare the Variable as Constant in C

There are a wide range of ways of making the variable as steady Using const keyword: The const catchphrase permits a software engineer to inform the compiler that a specific variable should...

5 minutes read.

Kruskal algorithm in C

Given a weighted graph, Kruskal's algorithm generates a spanning tree with the lowest possible weights. Start by creating an edge list for the given graph, including the weights. Sort the...

3 minutes read.

Merge and Merge sort with example in C

Assume we have two ordered Integer arrays, a[] and b[]. If we wish to combine them into another ordered array, such as c[], we can use the following straightforward technique. Compare...

3 minutes read.

Length of an Array Function in C

In C, there is no built-in function to get the length of an array. However, there are a few ways you can determine the length of an array. It is necessary...

15 minutes read.

FIFO Example in the C Language

FIFO is an acronym that means "First In, First Out." It is a data structure handling method in which the first element is handled first, and the last element is...

3 minutes read.

Difference between Pre-increment and Post-increment in C

Increment operators are the kind of operators that are used to increment the cost of the operand by way of 1. In different words, the increment operator is an operator...

4 minutes read.

strtok() and strtok_r() functions in C with examples

strtok() and strtok_r() functions in C with examples C offer various strtok() and strtok r() methods for a string to be separated by a certain delimiter. Dividing a string is a...

2 minutes read.

Types of Function in C

A function is a piece of code that accomplish a certain operation for a specific task. There are two types of functions in C: System-defined function (Library Function)User-defined function 1. System defined Function...

8 minutes read.

How to Calculate Time Complexity in C?

What is time complexity? An algorithm's time complexity measures how long it takes to complete a task in relation to the size of the input. It should be noted that the...

5 minutes read.

Local Labels in C

Anyone who has written programs in the C programming language is required to be familiar with the "go to" and "labels" used in C to navigate between functions. "Local labels"...

4 minutes read.

Difference between C and Java

C programming and Java programming are two of the earliest programming languages. C programming follows a procedural approach whereas Java programming follows an object-oriented approach. Java programming is a part...

3 minutes read.

Static in C

Static is a keyword that is used in the C programming language. It can be used both as variables and as functions. In other words, it can be declared both...

3 minutes read.

Fibonacci series in C

We have learned about the Fibonacci series in mathematics. For a quick recap, A Fibonacci series is the sequence of numbers following a certain pattern i.e., the next number should...

3 minutes read.

How to measure time taken by a function in C?

Measuring the time taken by a function is quite a complex task, because numerous methods are frequently not transferable to other platforms, measuring the execution time of a C programs...

5 minutes read.

String in C

String is a collection of character or group of characters. In array, string of character is terminated by a null value “\0” and enclose between double quote. We can declare...

2 minutes read.