| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 474 人关注过本帖
标题:有人可以帮忙把这个程序编辑完整么 万分感谢
只看楼主 加入收藏
jameszhpg
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-11-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
有人可以帮忙把这个程序编辑完整么 万分感谢
/* a program that compute perfect numbers */
/*

 perfect number is a number who factors adds up to itself.

For example; 6
factors are 1, 2, 3 and 1 + 2 + 3 = 6

Another example : 28
factors are: 1, 2, 4, 7, 14
and 1 + 2 + 4 + 7 + 14 = 28

This ia program that find 6 perfect numbers

*/
#include <stdio.h>

#define S    1    /* Starting Number */
#define N    6    /* Number of perfect number to find */
#define WRITEONLY    "w"

FILE    *fp;
long     p = S;

main( argc, argv )
      int argc ;
      char *argv[ ] ;
{
    long     f,sum;
    int     c = 1;

      if(argc == 2)
    {
        if ((fp=fopen(argv[1], WRITEONLY)) == NULL)
        {
            printf("%s: cannot open %s\n", argv[0], argv[1]);
            exit(1);
        }
    } else    fp = stdout ;
/****

Logic is missing here!


***/
}
搜索更多相关主题的帖子: 编辑 perfect example factors 
2011-11-26 15:13
mfh
Rank: 6Rank: 6
等 级:侠之大者
帖 子:179
专家分:411
注 册:2009-5-31
收藏
得分:20 
#include <stdlib.h>
#include <stdio.h>
#define S    1    /* Starting Number */
#define N    6    /* Number of perfect number to find */
#define WRITEONLY    "w"
FILE    *fp;
long     p = S;
main( argc, argv )
      int argc ;
      char *argv[ ] ;
{
    long     f,sum;
    int     c = 1;
    if(argc == 2)
    {
        if ((fp=fopen(argv[1], WRITEONLY)) == NULL)
        {
            printf("%s: cannot open %s\n", argv[0], argv[1]);
            exit(1);
        }
    } else    fp = stderr ;
/****
Logic is missing here!

***/
        for(f =1;p<=N ; f++)
        {      
                sum =0;
                for(c = 1 ;c <=f/2 ;c ++)
                {
                        if(f%c == 0)
                        {
                                sum += c;
                                fprintf(fp,"%d ",c);
                        }
                }
               
                if(sum == f)
                {
                        fprintf(fp,"==>[%d]f == %ld\n",p,f);
                        p++;
                }
               
                 fprintf(fp,"\n");
               
        }
         
        if(argc == 2)
              fclose(fp);
      
}
2011-11-26 15:45
mfh
Rank: 6Rank: 6
等 级:侠之大者
帖 子:179
专家分:411
注 册:2009-5-31
收藏
得分:0 
最好将数字【N】改为4或小于4来测试,因为这样子的数很少,需要运行很久。
2011-11-26 15:46
快速回复:有人可以帮忙把这个程序编辑完整么 万分感谢
数据加载中...
 
   



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

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