Power Function in CThis article will discuss the power function and its various examples in the C language. The power function is used to find the power of any given number. The power function is a predefined library function of the math.h header file, and we need to import the math.h header file in our program while using the pow() function. In other words, a pow() function is used to calculate the power of the base number (x) by raising the power of (y) as (xy). For example, we take base as 2 and power as 5, the power of a number using the pow(2, 5) function to return a value as the 32. Similarly, we pass 3 as the base and 4 as the exponent number to raise the power of the base number using the pow(3, 4), which returns results as 81. ![]() SyntaxThe pow() function has two integer arguments for raising the power of base value (x) by the exponent (y). Parameters:
Program to find the power of an integer number using the pow() functionLet's consider an example to get the power of an integer number using the pow() function in the C programming language. Program2.c Output Enter the base value from the user: 7 Enter the power value for raising the power of base: 5 7 to the power of 5 is = 16807 Program to calculate the power of double data value using the pow() functionLet's consider an example to demonstrate the pow() function using the double data values in the C programming language. Program2.c Output Enter the base value from the user: 2.9 Enter the power value for raising the power of base: 8.3 2.9 to the power of 8.3 is = 6884.99 Program to get the power of a number using a user-defined functionLet's consider an example to create a user-defined function to get the power of a number in the C programming language. Program1.c Output Enter the base value: 25 Enter the power value: 6 25 to the power 6 is = 244140625 Program to get the power of a number using the recursion function and pow() functionLet's consider an example to find the power of a number using the recursion function and pow() function in the C programming language. Program.c Output Enter the base value from the user 5 Enter the power value from the user 6 5 to the power of 6 is = 15625 ConclusionA power function is used to find the power of any numeric data (int, float, double) using the pow() function. A power function has two arguments: the base number and the exponent number. The base number represents the power to be calculated, and the exponent defines the power of the base value.
Next TopicMalloc in C
|