How to use the C language function pow?

In C language, the pow function can be used to calculate the power of a number.

The prototype of the pow function is as follows:

double pow(double x, double y);

In this equation, x is the base and y is the exponent. The function returns the result of x raised to the power of y.

Here is an example of using the pow function to calculate the square of a number:

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

int main() {
    double num, result;
    
    printf("请输入一个数:");
    scanf("%lf", &num);
    
    result = pow(num, 2);
    
    printf("该数的平方为:%.2lf\n", result);
    
    return 0;
}

In this example, first ask the user for a number, then use the pow function to calculate the square of that number, and print out the result.

bannerAds