C Language: pow function(Power)

C Programming allows us to perform mathematical operations through the functions defined in header file. The header file contains various methods for performing mathematical operations such as sqrt(), pow(), ceil(), floor() etc.

C Math Functions

In the C Programming Language, the pow function returns x raised to the power of y.

Syntax

The syntax for the pow function in the C Language is:




double pow(double x, double y);



Parameters or Arguments

A value used in the calculation where x is raised to the power of y.

A value used in the calculation where x is raised to the power of y.

Returns

The pow function returns x raised to the power of y. If x is negative and y is not an integer value, the pow function will return a domain error.

Required Header

In the C Language, the required header for the pow function is:




#include <math.h>



Applies To

In the C Language, the pow function can be used in the following versions:

  • ANSI/ISO 9899-1990

pow Example




/* Example using pow by c programming */

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value1, value2;
    double result;

    /* Assign the values we will use for the pow calculation */
    value1 = 4;
    value2 = 2;

    /* Calculate the result of value1 raised to the power of value2 */
    result = pow(value1, value2);

    /* Display the result of the calculation */
    printf("%f raised to the power of %f is %f\n", value1, value2, result);

    return 0;
}



When compiled and run, this application will output:

4.000000 raised to the power of 2.000000 is 16.000000




Instagram