- 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 in Mathematics in C++

The power of a number is the times a number is multiplied to itself. Also knows as *exponent or indices.*

a to the power b is b times a is multiplied by itself b times. 7 to the power 2 is 7^{2} also known as 7 square is valued 49.

Some common power values are −

A number to the power 0 gives 1.

A number to the power 1 gives the same number, as stated some multiplied once is the same.

A number to the negative power is n times division. Example, a

^{-3}= 1/a^{3}or (1/a)*(1/a)*(1/a)

Now, let’s do some programming based on the concept of power.

In this problem, we are given two numbers N and a. And we have to find whether N is equal to a to the power of some number.

Let’s take an example to understand the problem,

**Input **− N = 64 , a = 2

**Output **− Yes

A simple and effective solution will be a recursive division of the number. If it perfectly divides the number till the end the return TRUE otherwise FALSE.

## Example

Program to show the implementation of our solution

#include <iostream> using namespace std; bool isAPowerNumber(int x, long int y) { if (x == 1) return (y == 1); long int power = 1; while (power < y) power *= x; return (power == y); } int main() { int N = 625 , a = 5; if(isAPowerNumber(a, N)) cout<<N<<" is a power of "<<a; else cout<<N<<" is not power of "<<a; return 0; }

## Output

625 is a power of 5

- Related Questions & Answers
- Mathematics summation function in JavaScript
- How to multiply two vectors in R as in mathematics?
- Power Triangle and Power Factor in AC Circuits
- Finding power set for a set in JavaScript Power Set
- Find power of power under mod of a prime in C++
- What is Power Factor and Power Triangle?
- Power Set
- Power Function in C/C++
- Power of Two in C
- Power of Three in Python
- Power of Four in C++
- Power Flow in Synchronous Motor
- Get power using Math.pow in Java
- Reordered Power of 2 in C++
- Plotting power spectral density in Matplotlib