Skip to content

Commit 1303ff4

Browse files
committed
[Shreyash]: Added code to print table of power of 2
1 parent 4038467 commit 1303ff4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Write a program that takes a command-line argument n and prints table
3+
of the powers of 2 that are less than or equal to 2^n till 256 is reached..
4+
*/
5+
6+
const prompt = require("prompt-sync")();
7+
console.log();
8+
let n = parseInt(prompt(" Enter power : "))
9+
console.log(" Priniting the table of 2 till 2^n or 256 :");
10+
let result;
11+
let i = 1;
12+
while (result != 256 && i <= n) {
13+
result = Math.pow(2, i);
14+
console.log(" 2^" + i + ": " + result);
15+
i++;
16+
}
17+
console.log();

0 commit comments

Comments
 (0)