| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 487 人关注过本帖
标题:不懂的程序
只看楼主 加入收藏
gongqivictor
Rank: 1
来 自:武汉科大
等 级:新手上路
帖 子:32
专家分:0
注 册:2008-9-16
收藏
 问题点数:0 回复次数:1 
不懂的程序
一个经典的c程序,是求一个集合的所有子集,并显示出来

但其中的红字部分看不懂,好像有点多余,但经典程序里是不会有多余的句子的

求解哦~

 

 

 

#include  <stdio.h>
#include  <stdlib.h>

#define   MAXSIZE   20
#define   LOOP       1

void main(void)
{
     char digit[MAXSIZE];
     int  i, j;
     int  n;
     char line[100];

     

     printf("\nDirect Generation of All Subsets of a Set");
     printf("\n=========================================");
     printf("\n\nNumber of Elements in the Given Set --> ");
     

     gets(line);//从流中取一字符串     输入的应该是个字符串?
     n = atoi(line);//把字符串转换成长整型数   必须是数字?不然输出结果为0

     /* ---You'd better check to see if n is too large--- */

     for (i = 0; i < n; i++)  /* clear all digits to 0    */
          digit[i] = '0';

     printf("\n{}");          /* outpout empty set {}     */
     while (LOOP)
  {
   for (i = 0; i < n && digit[i] == '1'; digit[i] = '0', i++)
               ;              /* find first 0 position    */
         if (i == n)         /* if none, all pos. are 1  */  
    break;         /* thus all elem. are in set*/   
          else
               digit[i] = '1';/* now add one to this pos  */   //变成1之后,然后回去又变成0?

          for (i = 0; i < n && digit[i] == '0'; i++)
               ;              /* find first 1 position    */
          printf("\n{%d", i+1);  /* show its numner and   */
          for (j = i + 1; j < n; j++) /* others           */
               if (digit[j] == '1')
                    printf(",%d", j + 1);
          printf("}");
     }
搜索更多相关主题的帖子: 经典的 include c程序 
2008-10-07 12:05
gongqivictor
Rank: 1
来 自:武汉科大
等 级:新手上路
帖 子:32
专家分:0
注 册:2008-9-16
收藏
得分:0 
for (i = 0; i < n && digit[i] == '1'; digit[i] = '0', i++)
               ;              /* find first 0 position    */
         if (i == n)         /* if none, all pos. are 1  */  
    break;         /* thus all elem. are in set*/   
          else
               digit[i] = '1';/* now add one to this pos  */   //变成1之后,然后回去又变成0?


红字打掉了,嘿嘿,就是上面的
2008-10-07 12:06
快速回复:不懂的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014097 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved