Power Function in C Last Updated : 30 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice In C language, the pow() function is defined in the <math.h> header file and is used to calculate the exponent value of x raised to the power of y, i.e., xy. Basically, in C, the exponent value is calculated using the pow() function. Example: C #include <stdio.h> // Include math.h for the pow() function #include <math.h> int main() { double base = 5, exponent = 3, result; // Calculate the result of base // raised to the power of exponent result = pow(base, exponent); // Output the result printf("%.0f raised to the power of %.0f is %.0f\n", base, exponent, result); return 0; } Output5 raised to the power of 3 is 125 pow() in CTo use the pow() function in our program we need to include the <math.h> in our C program. The pow() function takes a double as input and returns a double as output. The pow() function has 3 different overloads that return values in double, float or long double based on the data type of input values. Syntax C //takes double as input and returns double double pow(double base, double exponent); //takes float as input and returns float float pow(float base, float exponent); //takes long double as // input and returns long double long double pow(long double base, long double exponent); Parametersx: base valuey: exponent valueReturn ValueThe power function may return the double value , floating point value, or long double value of x raised to the power y ( x y ) based on the values of x and y.Examples Using pow() Function C #include <stdio.h> #include <math.h> int main() { //taking double as input double x = 6.176, y = 4.832; printf("%f raised to power of %f is %f\n", x, y, pow(x, y)); //taking float as input float a = 3.14, b = 2.58; printf("%f raised to power of %f is %f\n", a, b, pow(a, b)); //taking long double as input long double p = 2.1591, q = 2.8642; printf("%Lf raised to power of %Lf is %f\n", p, q, pow(p, q)); return 0; } Output6.176 raised to power of 4.832 is 6617.56 3.14 raised to power of 2.58 is 19.146 2.1591 raised to power of 2.8642 is 9.06617 pow() Function with IntegersThe pow() function takes 'double' as the argument and returns a 'double' value. This function does not always work properly for integers. One such example is pow(5, 2). When assigned to an integer, it outputs 24 on some compilers and works fine for some other compilers. But pow(5, 2) without any assignment to an integer outputs 25. One another way can be using the round function to assign it to some integer type.This is because 52 (i.e. 25) might be stored as 24.9999999 or 25.0000000001 because the return type is double. When assigned to int, 25.0000000001 becomes 25 but 24.9999999 will give output 24.To overcome this and output the accurate answer in integer format, we can add 1e-9 or 0.000000001 to the result and typecast it to int e.g (int)(pow(5, 2)+1e-9) will give the correct answer(25, in the above example), irrespective of the compiler.Example 1: C Program to demonstrate the behavior of the pow() function with integers. C // C program to illustrate // working with integers in // power function #include <math.h> #include <stdio.h> int main() { int a, b; // Using typecasting for // integer result a = (int)(pow(5, 2) + 1e-9); b = round(pow(5,2)); printf("%d \n%d", a, b); return 0; } Output25 25Time Complexity: O(log(n))Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Power Function in C kartik Follow Improve Article Tags : C++ C Language C-Functions Practice Tags : CPP Similar Reads valarray pow() function in C++ The pow() function is defined in valarray header file. This function returns a valarray containing the results of the power operation on all the elements, in the same order. Syntax: pow(varr, n); Parameter: varr: This represents the valarray object.n: It represents a exponent value. Returns: This fu 2 min read scalbn() function in C++ The scalbn() function is defined in the cmath header file. This function is used to calculate the product of given number x and FLT_RADIX raised to the power n. Syntax:- float scalbn(float x, int n); or double scalbn(double x, int n); or long double scalbn(long double x, int n); or double scalbn(int 2 min read clock() function in C The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be 2 min read exp2() function in C++ STL The exp2() is a builtin function in C++ STL that computes the base-2 exponential function of a given number. It can also be written as 2num. Syntax: exp2(data_type num) Parameter: The function accepts a single mandatory parameter num which specifies the value of the exponent. It can be positive, neg 2 min read valarray exp() function in C++ The exp() function is defined in valarray header file. This function is used to calculate e raised to the power equal to the value of the element in valarray. Syntax: exp(varr); Parameter: This function takes a mandatory parameter varr which represents valarray. Returns: This function returns a vala 2 min read scalbln() function in C++ STL The scalbln() is a built-in function in C++ STL which takes two arguments and scales x by FLT_RADIX raised to the power n. The function returns the product of x and FLT_RADIX raised to the power n. FLT_RADIX: It is the value of the radix (integer base) of the exponent representation. Syntax: scalbln 2 min read C Library - exp() Function In C programming language, the exp() function is a built-in function of <math.h> library which is used to calculate the value of e (Euler's Number = 2.71828) raised to the power x where x is any real number. Syntax: double exp(double x);Arguments: This function takes only one argument of type 4 min read pow() function for complex number in C++ The pow() function for complex number is defined in the complex header file. This function is the complex version of the pow() function. This function is used to calculate the complex power of base x raised to the y-th power. Syntax: template<class T> complex<T> pow (const complex<T 2 min read exp() function C++ The exp() function in C++ returns the exponential (Euler's number) e (or 2.71828) raised to the given argument. Syntax for returning exponential e: result=exp() Parameter: The function can take any value i.e, positive, negative or zero in its parameter and returns result in int, double or float or l 2 min read exp() function for complex number in C++ The exp() function for complex number is defined in the complex header file. This function is the complex version of the exp() function. This function is used to calculate the base e exponential of a complex number z and returns the base-e exponential of complex number z. Syntax: template<class T 2 min read Like