用c++设计一个程序,求出100~200之间的所有素数
嵌入式吧
全部回复
仅看楼主
level 1
君如狂0384 楼主
用c++设计一个程序,求出100~200之间的所有素数并按每行五个素数的格式输出
2014年03月14日 00点03分 1
level 1
人!工!置!顶!
2014年03月14日 04点03分 2
level 6
#include<stdio.h>
#include<iostream>
using namespace std;
int su(int a);
int main()
{
int put,k=0;
for(int i=100;i!=201;i++)
{
put=su(i);
if(put!=0)
{
cout<<put;
cout<<" ";
k++;
if (k%5==0)
cout<<endl;
}
}
}
int su(int a)//用以判断是否为素数,是返回该数,不是返回0
{
bool p=1;//用以for返回
for(int i=2;i!=a;i++)
{
if(a%i==0)
{
p=0;
break;
}
}
if(p==1)
{
return a;
}
}
2014年03月15日 13点03分 5
level 6
好多人问这个…是不是老师布置作业了
2014年03月15日 13点03分 6
level 10
[大拇指]
2014年03月17日 06点03分 7
1