C++求大侠帮忙写作业

[复制链接]
查看11 | 回复1 | 2011-7-13 21:27:35 | 显示全部楼层 |阅读模式
编写函数fun(int m ,int*k,intxx[]),其功能是:将所有大于1小于m的非素数存入XX所指的数组中。非素数的个数通过K传回。
例如:
若输入17 则应输出9和4 6 8 9 10 12 14 15 16

回复

使用道具 举报

千问 | 2011-7-13 21:27:35 | 显示全部楼层
#include #include using namespace std;bool IsPrime(int x){
if(x==1) return false;
if(x==2) return true;
int k=sqrt(x);
for(int i=2;i<=k;++i)
if( x % i == 0 )
return false;
return true;}void fun(int m ,int *k,int xx[]){
int j=0;
for(int i=2,*k=0;i<m;++i)...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行