求[30,500]素数的个数
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 18:20:14
求[30,500]素数的个数
求[30,500]素数的个数
求[30,500]素数的个数
85个.
#include
void PrimeNumber(int n)
{
int i,j,count=0;
for(i=2;i<=n;i++)
{
for(j=2;j<=i;j++)
{if(i%j==0) break;}
if(j==i) {printf("%d ",i);count++;}
}
printf("\nAnd there are %d in all\n",count);
}
void main()
{
int n;
printf("The programme will give all the Prime Number no more than the number you input and give how many are they in all\n");
printf("\nPlease give an natural number:");
scanf("%d",&n);
if(n<=0) printf("Please give a natural number means it should greater than 0!\n");
else if(n==1) printf("No prime number less than or equal to 1!\n");
else
{
printf("The Prime Number less than %d are:\n",n);
PrimeNumber(n);
}
printf("\n");
}
C程序做的~