C ++ pow () - C ++ standarta bibliotēka

Funkcija pow () aprēķina bāzes skaitli, kas palielināts līdz eksponenta skaitļa jaudai.

Šī funkcija ir definēta galvenes failā.

(Matemātika) bāzes eksponents = pow (pamats, eksponents) (C ++ programmēšana)

pow () prototips (pēc standarta C ++ 11)

dubultā vara (dubultā bāze, dubultā eksponents); float pow (pludiņa pamatne, pludiņa eksponents); garā dubultā vara (garā dubultā bāze, garā dubultā eksponente); Paaugstinātā vara (1. tipa bāze, 2. tipa eksponents); // Citu argumentu tipiem

Tā kā C ++ 11, ja kāds arguments, kas nodots pow (), ir long double, atgriešanās tips Promoted ir long double. Ja nē, atgriešanās veids ir Promoted double.

pow () Parametri

Funkcijai pow () ir divi argumenti:

  • bāze - bāzes vērtība
  • eksponents - bāzes eksponents

pow () atgriešanās vērtība

Funkcija pow () atgriež bāzi, kas paaugstināta uz eksponenta spēku.

1. piemērs: Kā pow () darbojas C ++?

 #include #include using namespace std; int main () ( double base, exponent, result; base = 3.4; exponent = 4.4; result = pow(base, exponent); cout << base << "^" << exponent << " = " << result; return 0; )

Palaidot programmu, izeja būs:

 3,4 4,4 = 218,025

2. piemērs: pow () ar dažādu argumentu kombināciju

 #include #include using namespace std; int main () ( long double base = 4.4, result; int exponent = -3; result = pow(base, exponent); cout << base << "^" << exponent << " = " << result << endl; // Both arguments int // pow() returns double in this case int intBase = -4, intExponent = 6; double answer; answer = pow(intBase, intExponent); cout << intBase << "^" << intExponent << " = " << answer; return 0; )

Palaidot programmu, izeja būs:

 4,4 -3 = 0,01117393 -4 6 = 4096 

Interesanti raksti...