码迷,mamicode.com
首页 > 编程语言 > 详细

C语言之计算log2

时间:2016-08-02 17:05:35      阅读:1251      评论:0      收藏:0      [点我收藏+]

标签:

#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
*/
//注意:在两个数做运算时,只要有一个是浮点数,计算的结果均为浮点数!

C语言之计算log2

标签:

原文地址:http://www.cnblogs.com/gcter/p/5729712.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!