C pow()

The pow() function takes two arguments (base value and power value) and, returns the power raised to the base number. For example,

[Mathematics] xy = pow(x, y) [In programming]

The pow() function is defined in math.h header file.


C pow() Prototype

double pow(double x, double y)

The first argument is a base value and second argument is a power raised to the base value.

To find the power of int or a float variable, you can explicitly convert the type to double using cast operator.

int base = 3;
int power = 5;
pow(double(base), double(power));

Example: C pow() function

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

int main()
{
    double base, power, result;

    printf("Enter the base number: ");
    scanf("%lf", &base);

    printf("Enter the power raised: ");
    scanf("%lf",&power);

    result = pow(base,power);

    printf("%.1lf^%.1lf = %.2lf", base, power, result);

    return 0;
}

Output

Enter the base number: 2.5
Enter the power raised: 3.4
2.5^3.4 = 22.54

Before we wrap up, let’s put your knowledge of C math pow() to the test! Can you solve the following challenge?

Challenge:

Write a function to calculate the power of two for a given number.

  • For example, with input num = 3, the return value should be 8.
Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges