Power Function in C
Level 3111 keystrokes
Defines a function to calculate the power of a number.
C code
// b is the base and e the exponent1int power(int b, int e) { // Start at 1, which is also the answer when e is 02 int r = 1; // Multiply r by b exactly e times3 for (int i = 0; i < e; i++) r *= b; // Return the result to the caller4 return r;5}// 2 to the power 8 = 256 (C has no ^ power operator; ^ is XOR)6printf("%d", power(2, 8));Output
256
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 6(× 4)× 4,× 3=× 3"× 2+× 2{× 1}× 1*× 1