我是靠谱客的博主 魁梧彩虹,最近开发中收集的这篇文章主要介绍[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n.c[Loops]D. Liang 4.20 Printing Prime numbers between 2 and nDescriptionInputOutputNOTE:Sample InputSample Output,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n

Description

Write a program that reads an interger n, then print all the prime numbers between 2 and n, inclusively.

Input

An integer n (2<=n<=2000).

Output

All the prime number between 2 and n, inclusively.
You should display eight prime numbers per line, specify the width of each number’s print field to 5, justify the output to right.

NOTE:

  1. There is NO SPACE at the end of each line.
  2. There is A NEWLINE (n) at the end of last line iff it has eight number.

That is (. indicates <space> and ¬ indicates &lt;newline>)

....2

or

....2....3....5....7...11...13...17...19¬

Sample Input

59

Sample Output


2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
//
Date:2020/3/19
//
Author:xiezhg5
#include <stdio.h>
#include <math.h>
int main(void)
{
int count=0;
int i,j,k;
int m,n;
m=2;
scanf("%d",&n);
for(i=m;i<=n;i++)
{
k=sqrt(i);
//遍历2到√i的数即可 
for(j=2;j<=k;j++)
if(i%j==0)
{
break;
//不是素数立即退出循环 
}
if(j>=k+1)
{
if(i==1)
count=count;
else
{
printf("%5d",i);
count++;
if(count%8==0)
//注意输出要求 
printf("n");
}
}
}
printf("n");
return 0;
}

最后

以上就是魁梧彩虹为你收集整理的[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n.c[Loops]D. Liang 4.20 Printing Prime numbers between 2 and nDescriptionInputOutputNOTE:Sample InputSample Output的全部内容,希望文章能够帮你解决[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n.c[Loops]D. Liang 4.20 Printing Prime numbers between 2 and nDescriptionInputOutputNOTE:Sample InputSample Output所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部