1-1000的素数用pascal语言怎么求?

[复制链接]
查看11 | 回复4 | 2011-8-24 04:31:16 | 显示全部楼层 |阅读模式
回复

使用道具 举报

千问 | 2011-8-24 04:31:16 | 显示全部楼层
用筛选法直接打的理解下思路就行了f:array[0..1000]ofboolean;先初始化fillchar(f,sizeof(f),1);fori:=2to1000doiffthen//i是素数beginwriteln(i);2到1000里i的倍数都设为false;end;
回复

使用道具 举报

千问 | 2011-8-24 04:31:16 | 显示全部楼层
vari:integer;functioncheck(t:longint):boolean;vari,j:longint;begincheck:=true;fori:=2totrunc(sqrt(t))doiftmodi=0thenexit(false);end;beginfori:=2to1000doifcheck(i)thenwrite(i,\'\');end.
回复

使用道具 举报

千问 | 2011-8-24 04:31:16 | 显示全部楼层
函数法varn,i:longint;functionss(n:longint):boolean;vari:longint;beginfori:=2tosqrt(trunc(n))doifnmodi=0thenexit(false);exit(true);end;beginfori:=2to1000do//由于1不是函数直接从2开始ifss(i)thenwrite(i,\'\');end.
回复

使用道具 举报

千问 | 2011-8-24 04:31:16 | 显示全部楼层
筛法打表、
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行