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 49787e2 commit d4b53f5Copy full SHA for d4b53f5
Repetition Problems/For Loop/PowerOfTwo.js
@@ -0,0 +1,15 @@
1
+/*
2
+ Write a program that takes a command-line argument n and prints table of the powers of 2
3
+ that are less than or equal to 2^n.
4
+*/
5
+
6
+const prompt = require("prompt-sync")();
7
+console.log();
8
+let power = parseInt(prompt(" Enter the power : "))
9
+let result = 1;
10
+console.log(" Printing powers of 2 :");
11
+for (let i = 1; i <= power; i++) {
12
+ result = result * 2;
13
+ console.log(" 2^" + i + " = " + result);
14
+}
15
0 commit comments