标签:ios names ret end 思路 次方 main using mic
思路:将k看作二进制数,每次与1,若得到结果为1,就相乘.#include<iostream>
using namespace std;
int main()
{
int n = 2, k = 8;
int res = 1;
cout<<n<<"的"<<k<<"次方等于:";
while(k)
{
if(k & 1)
{
res *= n;
}
n *= n;
k >>= 1;
}
cout<<res<<endl;
return 0;
}
标签:ios names ret end 思路 次方 main using mic
原文地址:https://blog.51cto.com/14472348/2474986