2的10次方
1 #include <iostream> 2 3 int main() 4 { 5 int value = 2, counts = 10, res = 1; 6 for (int i=0; i<counts; i++) 7 res *= value; 8 std::cout << "res:" << res << std::endl; 9 10 return 0; 11 }
另外一种方法
#include <stdio.h> int power(int base, int powerCounts) { int temp=base, result=1; do{ if(powerCounts&1)result*=temp; temp*=temp; }while(powerCounts>>=1); return result; } int main() { int r = power(2,10); printf("r:%d\n",r); return 0; }