C 求某个范围的所有素数 SDUT


Description

求小于n的所有素数,按照每行10个显示出来。


Input

输入整数n(n<10000)。


Output

每行10个依次输出n以内(不包括n)的所有素数。如果一行有10个素数,每个素数后面都有一个空格,包括每行最后一个素数。


Sample
Input

100


Output

2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97


Hint

请注意题目中求的是小于n的所有素数。


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,j;
    int count=0;
    scanf("%d",&n);
    for(i=2; i<n; i++) //for循环控制范围;
        {
            for(j=2; j<i; j++) //一个判断素数过程;
            {
                if(i%j==0)
                    break;

            }
            if(i==j)
            {
                printf("%d ",j); //每一个数后面都有空格;
                count++;
            }
            if(count%10==0)
                printf("\n");
        }



    return 0;
}

发布了136 篇原创文章 · 获赞 95 · 访问量 2309

猜你喜欢

转载自blog.csdn.net/zhangzhaolin12/article/details/103979300