Compute integer powers of 2
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Compute integer powers of 2.
using System;
public class Power {
public static void Main() {
int e;
int result;
for(int i=0; i < 10; i++) {
result = 1;
e = i;
while(e > 0) {
result *= 2;
e--;
}
Console.WriteLine("2 to the " + i +
" power is " + result);
}
}
}
Related examples in the same category