- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Power Function in C/C++

Power function is used to calculate the power of the given number.

The pow function find the value of a raised to the power b i.e. a^{b}.

## Syntax

double pow(double a , double b)

It accepts a double integers as input and output a double integer as output. It *pow()* function is defined in *math.h* package.

If you pass an integer to the power function, the function converts it into double data type. But there's an issue with this, sometimes this conversion might store this as a lower double. For example, if we pass 3 and is converted as 2.99 then the square is 8.99940001 which converts into 8. But this is an error although it comes rarely but to remove this error 0.25 is added to it.

## Example Code

#include <stdio.h> #include <math.h> int main() { double x = 6.1, y = 2; double result = pow(x, y); printf("%f raised to the power of %f is %f \n" ,x,y, result ); // Taking integers int a = 5 , b = 2; int square = pow(a,b); printf("%d raised to the power of %d is %d \n", a,b, square ); return 0; }

## Output

6.100000 raised to the power of 2.000000 is 37.210000 5 raised to the power of 2 is 25

- Related Questions & Answers
- Write a power (pow) function using C++
- Power in Mathematics in C++
- Power Spectral Density (PSD) and Autocorrelation Function
- Power of Two in C
- Power of Four in C++
- Find power of power under mod of a prime in C++
- Reordered Power of 2 in C++
- C program to generate the value of x power n using recursive function
- Power Set in Lexicographic order in C++
- Power Triangle and Power Factor in AC Circuits
- Sort Integers by The Power Value in C++
- Find sub-string with given power in C++
- What is Power Factor and Power Triangle?
- Power Set
- How to calculate fractional power using C#?

Advertisements