C语言之计算log2

#include<stdio.h>
int main()
{
int num,count=0,i=0,ret=0;
scanf("%d",&num);
count=num;
while(num>1)
{
num/=2;
ret++;
}
printf("log2 of %d = %d\n",count,ret);

return 0;
}
/*
64
log2 of 64 = 6
Press any key to continue
*/
//注意:在两个数做运算时,只要有一个是浮点数,计算的结果均为浮点数!

posted @ 2016-08-02 16:13  A-inspire  Views(4232)  Comments(0Edit  收藏  举报