Computer Programming || Gaming || Technology || ai

how to use pow in c++


russell the programmer || russelltheprogrammer.com

To use exponencial or power , there is a library functions named pow().
Some example in c++ given below:


double pow( double x, int y ); // C++ only
float pow( float x, float y ); // C++ only
float pow( float x, int y ); // C++ only
long double pow( long double x, long double y ); // C++ only
long double pow( long double x, int y ); // C++ only

Even you can also use pow() function as below method:

double pow( double x, double y );
float powf( float x, float y );
long double powl( long double x, long double y );

Let’s See Some Code in C++:

#include <bits/stdc++.h>

using namespace std;

int main()
{
double x = 7.0, y = 9.0, z;

z = pow( x, y );
printf( “%.1f to the power of %.1f is %.1f\n”, x, y, z );

return 0;
}

Output:

7.0 to the power of 9.0 is 40353607.0

 

Another code to calculate the area of a circle:

#include <bits/stdc++.h>

using namespace std;

int main()
{
int r;
cin>>r;
float area=3.14159*pow(r,2);
cout<<area<<endl;

return 0;
}

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *




Calender

October 2020
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031