标题:……gets(line);…… line是一个数组名。这句有错没有?
取消只看楼主
jxt598598
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2007-6-13
结帖率:100%
 问题点数:0 回复次数:0 
……gets(line);…… line是一个数组名。这句有错没有?
……
gets(line);
……
line是一个数组名。这句有错没有?


/* ------------------------------------------------------ */
/* PROGRAM Subset Listing :                               */
/*    This program lists all subsets, including empty set,*/
/* of a given set with elements {1,2,...,n} by using a    */
/* direct generation method.                              */
/*                                                        */
/* Copyright Ching-Kuang Shene               July/04/1989 */
/* ------------------------------------------------------ */

#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);

     /* ---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  */

          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("}");
     }
}


[[it] 本帖最后由 jxt598598 于 2008-3-7 20:31 编辑 [/it]]
搜索更多相关主题的帖子: line gets 
2008-03-06 22:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-202296-1-1.html




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

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