We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5bf4b3 commit f35e6b9Copy full SHA for f35e6b9
Math/NextPow2/nextpow2.cpp
@@ -0,0 +1,26 @@
1
+#include <iostream>
2
+
3
+/**
4
+ * nextpow2 - Implementation of Next Power of 2
5
+ */
6
+int nextpow2(int n)
7
+{
8
+ int c = 0;
9
+ if (n < 1)
10
+ return 1;
11
+ --n;
12
+ while (n)
13
+ {
14
+ ++c;
15
+ n >>= 1;
16
+ }
17
+ return 1 << c;
18
+}
19
20
+int main()
21
22
+ int n;
23
+ std::cin >> n;
24
+ std::cout << nextpow2(n) << '\n';
25
+ return 0;
26
0 commit comments