编写程序,输入一个数n,统计出2到n之间的 所有素数个数。

用C 语言来写

第1个回答  2009-03-22
#include "stdio.h"
void main()
{
int i,j,a,b,n;
scanf("%d",&n);
for (i=3;i<=n;i++)
{
b=0;
for (j=2;j<i;j++)
{
a=i%j;
if (a==0) b=1;
}
if (b==0) printf("%d,",i);
}
}本回答被提问者和网友采纳
第2个回答  2009-03-22
Write two top methods ,one is to calculate the sum ,another is to sort the prime numbers between 2 and n. In the main method ,you can take advantage for loop.so much for this!
passing by!!!!!
第3个回答  2009-03-22
才5分。。。- -
第4个回答  2018-04-19
我试过了,是对的!
第5个回答  2018-02-04
#include "stdio.h"
int main()
{
int n, i, a, flag, j=0;
scanf("%d",&n);
for(i=2;i<=n;i++)
{
flag=0;
for(a=2;a<i;a++)
if(i%a==0)
{
flag=1;
break;
}
if(flag)
continue;
j++;
}
printf("%d\n",j);
}