Calculate 2 to the power of N
// Returns "double" value
1 2 3 4 private double TwoPowerN(int n) 5 { 6 int k; 7 int i = 1; 8 9 for (k=1; k <= n; k++) 10 { 11 i = i * 2; 12 } 13 return i 14 }
DZone Snippets > dubby > math
12978 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 3 4 private double TwoPowerN(int n) 5 { 6 int k; 7 int i = 1; 8 9 for (k=1; k <= n; k++) 10 { 11 i = i * 2; 12 } 13 return i 14 }