C语言求对数

求以2为底,x的对数:

#include

int main()
{
int x;
int ret = 0;

scanf("%d", &x);
int t = x;
while ( x > 1 ) {
x /= 2;
ret ++;
}
printf("log2 of %d is %d.", t, ret);

return 0;
}


你可能感兴趣的:(C语言,C)