Algorithm Gossip: 格雷码(Gray Code)
2015-02-04 17:04
260 查看
/**************************************** * File Name : arithmetic.c * Creat Data : 2015.2.4 * Author : ZY *****************************************/ /*Algorithm Gossip: 格雷码(Gray Code)*/ #include <stdio.h> #define MAXBIT 20 #define TRUE 1 #define CHANGE_BIT(x) x=((x) == '0'?'1':'0') #define NEXT(x) x=(1-(x)) int main(void) { char digit[MAXBIT]; int i,bits,odd; printf("输入位元数:"); scanf("%d",&bits); for(i = 0;i < bits;i++) { digit[i] = '0'; printf("0"); } printf("\n"); odd = TRUE; while(1) { if(odd) { CHANGE_BIT(digit[0]); } else { for(i = 0;i < bits&&digit[i] == '0';i++) { ; } if(i == bits-1) { break; } CHANGE_BIT(digit[i+1]); } for(i = bits-1;i >= 0;i--) { printf("%c",digit[i]); } printf("\n"); NEXT(odd); } return 0; }
相关文章推荐
- Algorithm-Gossip(1) 河内之塔 / 汉罗塔
- AlgorithmGossip (19) 完美数
- [LeetCode]—Gray Code 计算格雷码
- [LeetCode 89] Gray Code (格雷码问题)
- 笔试真题-递归方式计算某一正整数n的格雷码(Gray Code )
- Algorithm-Gossip(2) 费布拉切数列
- 算法学习 - Gray Code(格雷码)的解释和c++实现
- Algorithm Gossip: 最大访客数
- gray code(格雷码)
- c++实现gray code(格雷码)
- leetcode89-Gray Code(格雷码)
- Algorithm-Gossip(3) 巴斯卡三角形
- Algorithm Gossip (END)
- [LeetCode] 89. Gray Code 格雷码
- 第七次作业格雷码(Gray code)序列NO.1
- Algorithm Gossip: 稀疏矩阵
- LeetCode 89: Gray Code 格雷码
- Gray Code - 格雷码
- Algorithm-Gossip(4) 三色棋(Three_Color_Flag)
- 生成格雷码(Gray Code)