Power of Three
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
/*************************************************************************
> File Name: LeetCode326.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: 2016年05月10日 星期二 02时42分09秒
************************************************************************/ /************************************************************************* Power of Three Given an integer, write a function to determine if it is a power of three. Follow up:
Could you do it without using any loop / recursion? ************************************************************************/ #include "stdio.h" int isPowerOfThree(int n) {
double tmp = log10(n)/log10();
return tmp == (int)tmp ? : ;
} int main()
{
int n = ;
int ret = isPowerOfThree(n);
printf("%d\n",ret); n = ;
ret = isPowerOfThree(n);
printf("%d\n",ret); return ;
}