C语言编程找出100以内素数
6个回答
展开全部
# include <stdio.h>
# include <math.h>
void main()
{
int i,q,n,m;
printf("please enter the number\n");
scanf("%d",&m);
printf("There are prime numbers between 1 and %d\n",m);
for(i=1;i<=m;i++)
{
q=(int)sqrt(i);
for(n=2;n<=i;n++)
{
if(i%n==0) break;
}
if(n>q) printf("%d ",i);
}
printf("\n");
}
# include <math.h>
void main()
{
int i,q,n,m;
printf("please enter the number\n");
scanf("%d",&m);
printf("There are prime numbers between 1 and %d\n",m);
for(i=1;i<=m;i++)
{
q=(int)sqrt(i);
for(n=2;n<=i;n++)
{
if(i%n==0) break;
}
if(n>q) printf("%d ",i);
}
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询