Search This Blog

Wednesday, 16 November 2016

C Program to Calculate the Power of a Number Using pow() Function

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

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

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

    printf("Enter an exponent: ");
    scanf("%lf", &exponent);

    // calculates the power
    result = pow(base, exponent);

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

    return 0;
}
Output
Enter a base number: 2.3
Enter an exponent: 4.5
2.3^4.5 = 42.44

No comments:

Post a Comment