C program to find power of a number using pow function

Write a C program to input any two numbers x and y and find their power using inbuilt pow() function. How to find power of two numbers in C programming. How to use pow() function in C programming. C program to compute power of two numbers using predefined library function.

Example
Input

Enter base: 5
Enter exponent: 2

Output

x ^ y = 25

Required knowledge

Fundamentals of C, Data types, Talking user input in C

Program to find power of a number

/**
 * C program to find power of any number
 */

#include <stdio.h>
#include <math.h> //Used for pow() function

int main()
{
    double x, y, power;

    // Input two numbers from user to calculate power
    printf("Enter base: ");
    scanf("%lf", &x);
    printf("Enter exponent: ");
    scanf("%lf", &y);

    // Calculates x^y 
    power = pow(x, y);

    printf("x ^ y = %.2lf", power);

    return 0;
}

Note: %.2lf is used to print fractional value up to 2 decimal places.

Before moving to next program learn to find power of a number using other programming methods.

Output

Enter base: 5
Enter exponent: 3
x ^ y = 125

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>