You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
387 B

#include<bits/stdc++.h>
using namespace std;
int quick(int a,int b)
{
int s = 1;
while (b > 0) {
if (b & 1) {//b=b>>1保证了在最后一步肯定会执行该if判断
s = s * a;
}
a = a * a;
cout<<"b="<<b<<endl;
cout<<"s="<<s<<endl;
cout<<endl;
b = b >> 1;
}
return s;
}
int main() {
printf("%d",quick(2,10));
return 0;
}