#include <stdio.h>
#include <math.h>
void main()
{
int i,j,n=0;
for(i=100;i<=200;i++)
{
for(j=2;j<=sqrt(i);j++)
if(i%j==0)
break;
if(j>sqrt(i))
{
printf("%d ",i);
n=n+1;
}
printf("%d",n);
}
}
我是新手,能帮我看看错哪吗?还有怎么输出素数个数??
要是先输出素数个数呢?
追答要么采用数组,要么采用递归!
先输出个数,需要先统计出个数,所以必须得到这个数才能输出!
当然你也可以跑两遍你的代码,第一次只统计个数,第二次输出每个素数!(如果你是初学者,还没有学到数组和递归方法,可以使用这种方式)
/*
101 103 107 109 113 127 131 137 139 149
151 157 163 167 173 179 181 191 193 197
199
共有21个素数
Press any key to continue
*/
#include <stdio.h>那要是先输出个数腻??
追答那就把素数结果先保存到一个数组里,先输出了个数,再输出素数。
int main()