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 K kartik Follow Improve Article Tags : C Language C-Functions Explore C Programming Language Tutorial 4 min read C BasicsC Language Introduction 6 min read Features of C Programming Language 3 min read C Programming Language Standard 6 min read C Hello World Program 1 min read Compiling a C Program: Behind the Scenes 4 min read C Comments 3 min read Tokens in C 4 min read Keywords in C 2 min read C Variables and ConstantsC Variables 4 min read Constants in C 4 min read Const Qualifier in C 6 min read Different ways to declare variable as constant in C 2 min read Scope rules in C 5 min read Internal Linkage and External Linkage in C 4 min read Global Variables in C 3 min read C Data TypesData Types in C 5 min read Literals in C 4 min read Escape Sequence in C 5 min read bool in C 5 min read Integer Promotions in C 2 min read Character Arithmetic in C 2 min read Type Conversion in C 4 min read C Input/OutputBasic Input and Output in C 4 min read Format Specifiers in C 5 min read printf in C 5 min read scanf in C 3 min read Scansets in C 2 min read Formatted and Unformatted Input/Output in C 6 min read C OperatorsOperators in C 11 min read Arithmetic Operators in C 5 min read Unary Operators in C 5 min read Relational Operators in C 4 min read Bitwise Operators in C 6 min read C Logical Operators 4 min read Assignment Operators in C 4 min read Increment and Decrement Operators in C 4 min read Conditional or Ternary Operator (?:) in C 3 min read sizeof operator in C 3 min read Operator Precedence and Associativity in C 7 min read C Control Statements Decision-MakingDecision Making in C (if , if..else, Nested if, if-else-if ) 7 min read C - if Statement 4 min read C if else Statement 3 min read C if , else if ladder 4 min read Switch Statement in C 5 min read Using Range in switch Case in C 2 min read C - Loops 6 min read C for Loop 4 min read while Loop in C 5 min read do...while Loop in C 4 min read For vs. While 4 min read Continue Statement in C 4 min read Break Statement in C 5 min read goto Statement in C 4 min read C FunctionsC Functions 6 min read User-Defined Function in C 6 min read Parameter Passing Techniques in C 3 min read Function Prototype in C 4 min read How can I return multiple values from a function? 3 min read main Function in C 5 min read Implicit Return Type int in C 2 min read Callbacks in C 4 min read Nested Functions in C 4 min read Variadic Functions in C 5 min read _Noreturn function specifier in C 2 min read Predefined Identifier __func__ in C 2 min read C Library math.h Functions 6 min read C Arrays & StringsC Arrays 7 min read Properties of Array in C 7 min read Multidimensional Arrays in C - 2D and 3D Arrays 8 min read Initialization of Multidimensional Array in C 4 min read Pass Array to Functions in C 3 min read How to pass a 2D array as a parameter in C? 3 min read What are the data types for which it is not possible to create an array? 2 min read How to pass an array by value in C ? 2 min read Strings in C 6 min read Array of Strings in C 3 min read What is the difference between single quoted and double quoted declaration of char array? 2 min read C String Functions 6 min read C PointersC Pointers 9 min read Pointer Arithmetics in C with Examples 10 min read C - Pointer to Pointer (Double Pointer) 5 min read Function Pointer in C 6 min read How to Declare a Pointer to a Function? 2 min read Pointer to an Array | Array Pointer 5 min read Difference between constant pointer, pointers to constant, and constant pointers to constants 3 min read Pointer vs Array in C 1 min read Dangling, Void , Null and Wild Pointers in C 6 min read Near, Far and Huge Pointers in C 4 min read restrict Keyword in C 3 min read Like