C program to find power of a number

In this article, we are going to learn how to find the power of a number. We will learn about the pow() function which is available in C standard library. The header file required for this function is.

1. C Pow() function


The C library function double pow(double num, double x) returns num raised to the power of x.

Syntax of pow() fucntion:

double pow(double num, double x)

Parameters

  • num : This is the floating point base number value.
  • x :This is the floating point power value.

Return Value

This function returns the result of raising num to the power x.

C Program to find power of a number


Let us see our code example to calculate the power of a number.

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

int main()
{
    long number, expo, result;

 
    printf("Please enter the number to calculate its power: ");
    scanf("%ld", &number);
    printf("Please enter the exponent: ");
    scanf("%ld", &expo);

    
    result = pow(number, expo);

    printf("We just calculated %ld raised to the power %ld = %ld", number, expo, result);

    return 0;
}

Output

Please enter the number to calculate its power: 6
Please enter the exponent: 2
We just calculated 6 raised to the power 2 = 36