342.Power of Four

桃扇骨 2022-06-09 05:38 313阅读 0赞
  1. /*
  2. Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
  3. */
  4. bool isPowerOfFour(int num){
  5. int i;
  6. double test=(double)(num);
  7. for(i=0;i<100;i++)
  8. {
  9. if(test==1)
  10. return true;
  11. else if(test<1)
  12. return false;
  13. else
  14. test = test / 4;
  15. }
  16. return;
  17. }

发表评论

表情:
评论列表 (有 0 条评论,313人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Gang of Four设计模式

    设计模式有两种分类方法:根据目的和根据模式的作用范围. 一.根据目的来分 1.创建型 用于描述"怎样创建对象",它的主要特点是将"对象的创建和使用