In some programming languages, you can do exponentiation directly with the ^ operator. But while working on a problem, I found out that in C++, you have to use the pow function to do exponentiation. This article introduces two functions: pow, which does exponentiation for you, and sqrt, which takes square roots.
| sqrt | pow | |
| What it does | Square root | Exponentiation |
| Library | math.h | math.h |
1. Square root:
Format: result=sqrt(the number you want the square root of)Example: get the square root of 9
#include
#includeusing namespace std;
int main()
{
cout <2. Exponentiation:
Format: result=pow(x, y)Example: get 2 to the power of 4
#include
#include
using namespace std;
int main()
{
cout <