Skip to content

Commit d4b53f5

Browse files
committed
[Shreyash]: Added code to print table of power of 2
1 parent 49787e2 commit d4b53f5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
console.log();

0 commit comments

Comments
 (0)