English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

Função C

Array C

Ponteiro C

String C

C Language Structure

C Language File

C Others

C Language Reference Manual

C library function pow() usage and example

Biblioteca padrão <math.h> C

The pow(x, y) function calculates the y-th power of the parameter x.

The pow() function takes two parameters (base value and power value) and then returns the power raised to the base. For example

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

C pow() prototype

double pow(double x, double y)

x -- Represents the floating-point value of the base. y -- Represents the floating-point value of the exponent.

To find the power of an int or float variable, you can use the explicit type conversion operator to convert the type to double.

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("Input base: ");
    scanf("%lf",&base);
    printf("Input exponent: ");
    scanf("%lf",&power);
    result = pow(base, power);
    printf("%.1lf^%.1lf = %.2lf", base, power, result);
    return 0;
}

Resultado de Saída

Entrar em Base: 2.5
Entrar em Exponencial: 3.4
2.5^3.4 = 22.54

Biblioteca padrão <math.h> C