您的位置:首页 > 编程语言 > C语言/C++

C语言实验——素数 (sdut oj)

2017-01-25 17:19 211 查看




C语言实验——素数

Time Limit: 1000MS Memory Limit: 65536KB


Problem Description

输出100->200之间的素数的个数,以及所有的素数。




Input





Output

100->200之间的素数的个数,以及所有的素数。




Example Input





Example Output

21
101 103 ... 197 199





Hint


Author

ZJGSU

参考代码

#include<stdio.h>
int main()
{
int i;
int temp;
int a = 0;
for(i = 100; i <= 200; i++)
{
for(temp = 2; temp < i; temp++)
{
if(i%temp == 0)
{
break;
}
}
if(temp == i)
{
a++;
}
}
printf("%d\n",a);
for(i = 100; i <= 200; i++)
{
for(temp = 2; temp < i; temp++)
{
if(i % temp == 0)
{
break;
}
}
if(temp == i)
{
printf("%d ",i);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  SDUT OJ c语言 for 素数