| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 347 人关注过本帖
标题:求助!!关于求素数。看不懂怎么错的
只看楼主 加入收藏
skywolfno1
Rank: 1
等 级:新手上路
帖 子:5
专家分:1
注 册:2009-7-22
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
求助!!关于求素数。看不懂怎么错的
#include <stdio.h>

#include "math.h"

#define N 101

main()

{

int i,j,line,a[N];

for(i=2;i<N;i++) a[i]=i;

for(i=2;i<sqrt(N);i++)

 for(j=i+1;j<N;j++)

 {

  if(a[i]!=0&&a[j]!=0)

  if(a[j]%a[i]==0)

  a[j]=0;}

printf("\n");

for(i=2,line=0;i<N;i++)

{

 if(a[i]!=0)

 {printf("%5d",a[i]);

 line++;}

 if(line==10)

 {printf("\n");

line=0;}

}

}


--------------------Configuration: s - Win32 Debug--------------------
Compiling...
s.cpp
E:\学习\w\s.cpp(17) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(17) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(19) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(19) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(21) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(21) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(21) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(21) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(23) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(23) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(23) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(23) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(25) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(25) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(25) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(25) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(33) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(33) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(35) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(35) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(37) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(37) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(39) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(39) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(41) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(41) : error C2018: unknown character '0xa1'
E:\学习\w\s.cpp(47) : warning C4508: 'main' : function should return a value; 'void' return type assumed
搜索更多相关主题的帖子: 素数 
2009-08-12 15:23
wangzhen_andy
Rank: 2
来 自:广州
等 级:论坛游民
帖 子:39
专家分:25
注 册:2008-9-22
收藏
得分:20 
#include <stdio.h>
 
#include <math.h>
 
#define N 101
 
void main()
{
    int i,j,line;
    int a[N];
    for (i = 2; i < N; i++)
    {
        a[i]=i;
    }
    for (i = 2; i < 10; i++)
        for (j = i + 1; j < N; j++)
        {
            if (a[i] != 0 && a[j] != 0)
                if (a[j] % a[i] == 0)
                    a[j] = 0;
        }
    printf("\n");
    for (i = 2, line = 0; i < N; i++)
    {
        if (a[i] != 0)
        {
            printf("%5d", a[i]);
            line ++;
        }
        if (line == 10)
        {
            printf("\n");
            line = 0;
        }
    }
 
}

自己编程要注意规范
2009-08-13 14:58
快速回复:求助!!关于求素数。看不懂怎么错的
数据加载中...
 
   



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

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