+ 6

What is pow on c++? How and when do you use it?

A code would be helpful thanks!

8th Aug 2017, 3:59 PM
HJ🐓TDM
3 ответов
+ 15
It means power or raised to... It gives the value for x raised to n eg:- 2^3 is 8 #include <iostream> #include <cmath> // Header needed using namespace std; int main() { cout<<pow(2,3); //outputs 8 return 0; }
8th Aug 2017, 4:26 PM
Frost
Frost - avatar
+ 9
As I learned quite recently, C++ is a language which does not have an exponentiation operator like ** or ^ Instead, it uses a regular method imported from its math module - pow(x, y) It shows you the y-th power of x, like pow(2,5) equals 2*2*2*2*2 or 32
8th Aug 2017, 4:43 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Power function is needed #include <cmath> library or #include <bits/stdc++.h> library For example : #include <bits/stdc++.h> using namespace std; int main (){ cout << pow(5,2) << endl; return 0; } Output: 25
9th Feb 2020, 8:40 PM
Kaneki Ken
Kaneki Ken - avatar