1. void binary(int n)
  2. {
  3. if(n < 1)
  4. printf("%s\n",A); // Assume A is a global variable
  5. else
  6. {
  7. A[n-1] = '0';
  8. binary(n-1);
  9. A[n-1] = '1';
  10. binary(n-1);
  11. }
  12. }

n=4时输出如下:

0000
1000
0100
1100
0010
1010
0110
1110
0001
1001
0101
1101
0011
1011
0111
1111

完整代码:

  1. #include<stdio.h>
  2. #include<stdio.h>
  3. char A[4];
  4.  
  5. /*
  6. Code obtained from
  7.  
  8. http://www.studyalgorithms.com
  9. */
  10.  
  11. void binary(int n)
  12. {
  13. if(n < 1)
  14. printf("%s\n",A); // Assume A is a global variable
  15. else
  16. {
  17. A[n-1] = '0';
  18. binary(n-1);
  19. A[n-1] = '1';
  20. /*
  21. Feel free to copy but please acknowledge studyalgorithms.com
  22. */
  23. binary(n-1);
  24. }
  25. }
  26.  
  27. int main(void)
  28. {
  29. binary(4);
  30. return 0;
  31. }

产生n bit所有可能的序列的更多相关文章

  1. 【夯实PHP基础】UML序列图总结

    原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...

  2. Windows10-UWP中设备序列显示不同XAML的三种方式[3]

    阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...

  3. 软件工程里的UML序列图的概念和总结

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...

  4. python序列,字典备忘

    初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...

  5. BZOJ 1251: 序列终结者 [splay]

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3778  Solved: 1583[Submit][Status][Discu ...

  6. 最长不下降序列nlogn算法

    显然n方算法在比赛中是没有什么用的(不会这么容易就过的),所以nlogn的算法尤为重要. 分析: 开2个数组,一个a记原数,f[k]表示长度为f的不下降子序列末尾元素的最小值,tot表示当前已知的最长 ...

  7. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  8. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  9. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  10. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

随机推荐

  1. JSplitPane详解

    摘自http://blog.163.com/xiexueyong1987@126/blog/static/1262673422010102711295541/ JSplitPane详解 pasting ...

  2. Linux内存点滴 用户进程内存空间

    Linux内存点滴 用户进程内存空间 经常使用top命令了解进程信息,其中包括内存方面的信息.命令top帮助文档是这么解释各个字段的. VIRT, Virtual Image (kb) RES, Re ...

  3. Android学习笔记__2__Android工程目录结构

    一.创建Android工程HelloWorld . src 文件夹里的是源文件 . Android2.2 是引用的类库,这些和 java 的都一样 . gen里面的类就是 ADT 自动生成的啦,一般只 ...

  4. [每日一题] 11gOCP 1z0-052 :2013-09-4 block header grows............................................A33

    转载请注明出处:http://write.blog.csdn.net/postedit/11100311 正确答案是:AD 要理解这道题就要去了解数据块的结构.引用OCPPPT中的一幅图: 从这幅图中 ...

  5. iOS8 Core Image In Swift:更复杂的滤镜

    iOS8 Core Image In Swift:自动改善图像以及内置滤镜的使用 iOS8 Core Image In Swift:更复杂的滤镜 iOS8 Core Image In Swift:人脸 ...

  6. JAVA反射机制示例,读取excel数据映射到JAVA对象中

    import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileInputStream; import ja ...

  7. 移动开发(webapp)过程中的小细节总结

    1.阻止旋转屏幕时自动调整字体大小 html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6 { -webkit-text-size-adj ...

  8. gdalwarp:变形工具

    1 gdalwarp:变形工具.包括投影.拼接.及相关的变形功能.此工具功能强大,但效率不高,使用时注意 gdalwarp [--help-general] [--formats]     [-s_s ...

  9. JavaScript中String对象的match()、replace() 配合正则表达式使用

    正则表达式由来已久,查找替换功能非常强大,但模板难记复杂. JavaScript中String对象的match().replace()这2个方法都要使用正则表达式的模板.当模板内容与字符串不相匹配时, ...

  10. Linux中yum的安装

    下载安装yum: wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz .tar.gz cd touch /etc/yum.conf c ...