Skip to content
Home » C Program to Find Power of a Number using pow() function

C Program to Find Power of a Number using pow() function

Learn about C Program to Find Power of a Number using pow() function in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to Find Power of a Number using pow() function

Pow() is a pre-defined function in C that is used to determine the power of a number. It requires two arguments. It is defined in the “math.h” header file. As a result, in order to use the pow() function, we must include this header file in our program.

The function pow() computes the y power. If x is negative, then y must be an integer. If x is 0, then y must be positive.

Program:

#include<stdio.h>
#include<math.h>
 int main()
 {
     int base, exponent;
     long power;

     printf("Enter base and Exponent: ");
     scanf("%d %d", &base, &exponent);

     power = pow(base,exponent);

     printf("Result = %ld",power);
     return 0;
 }

Output:

Enter base and Exponent: 9 2
Result = 81

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to find x power y using for loop
C Program to Find Power of a Number using while loop