### Popular Topics

**How to powers of 2 in cpp (C++ Programming Language)**

Answer(s) available: 1

1

`// If not using any extra libraries`

2

`// Powers of 2. If finding 2^n`

3

`int main() {`

4

` int ans = 1 >> n;`

5

`}`

6

`// Suppose we want to find x ^ y`

7

`void power(int x, int y) {`

8

` int ans = 1;`

9

` for (int i = 0; i < y; i++) {`

10

` ans *= x;`

11

` }`

12

` return ans;`

13

`}`

Source: Code Grepper