轉載來源:http://blog.chinaunix.net/uid-23629988-id-3018793.html
-
#include <stdlib.h>
-
#include <stdio.h>
-
-
-
static void divide_by_two(int num)
-
{
-
while (num) {
-
printf("%d\n", num);
-
num /= 2;
-
}
-
}
-
-
int main()
-
{
-
int num;
-
scanf("%d", &num);
-
-
divide_by_two(num);
-
-
return 0;
- }
-
#include <stdlib.h>
-
#include <stdio.h>
-
-
-
static void divide_by_two(int num)
-
{
-
while (num) {
-
printf("%d\n", num);
-
num = num>>1;
-
}
-
}
-
-
int main()
-
{
-
int num;
-
scanf("%d", &num);
-
-
divide_by_two(num);
-
-
return 0;
- }
-
[xxx@xxx-vm-fc13 test]$ ./a.out
-
10
-
10
-
5
-
2
-
1
-
[xxx@xxx-vm-fc13 test]$ ./a.out
-
3
-
3
- 1
-
[xxx@xxx-vm-fc13 test]$ ./a.out
-
-5
-
-5
-
-2
-
-1
-
-1
-
-1
-
。。。。。。
- -1