- #include<stdio.h>
- #include<stdbool.h>
- bool isPowerofTwo(int n){
- while(n%2==0){
- n=n/2;
- }
- if(n==1){
- return true;
- }
- else{
- return false;
- }
- }
- int main(){
- printf("%d\n",isPowerofTwo(4));
- printf("%d\n",isPowerofTwo(8));
- printf("%d\n",isPowerofTwo(256));
- printf("%d\n",isPowerofTwo(565));
- }
找出二的N次方
最新推荐文章于 2021-07-27 02:48:13 发布