用C语言判断101-200之间有多少个素数,并输出所有素数。

//好像行不通。
/*#include <stdio.h>
#include <math.h>

int main()
{
int i,j,k,leap=1;
int count=0;

for (i=101; i<=200; i++)
{
k=sqrt(i+1);
for (j=2; j<=k; j++)
{

if (i%j==0)
{
leap=0;
break;
}
}

if (leap)
{
count++;
printf("%d ",i);
if (count % 5 == 0)
printf("\n");
}

leap=1;
}
return 0;
} */
这个好像不对啊~

/*
101 103 107 109 113 127 131 137 139 149
151 157 163 167 173 179 181 191 193 197
199
共有素数 : 21个。
*/
#include <stdio.h>
#include <math.h>
int main() {
int i,j,k,leap;
int count = 0;
for(i = 101; i <= 200; i++) {
leap = 1;
k = (int)sqrt((double)i);
for(j = 2; (j <= k) && leap; j++) {
if(i % j == 0) {
leap = 0;
break;
}
}
if(leap) {
if(count % 10 == 0) printf("\n");
printf("%d ",i);
count++;
}
}
printf("\n共有素数 : %d个。\n",count);
getchar();
return 0;
}追问

/tmp/ccrXjhKT.o: In function `main':
未命f 名.c:(.text+0x40): undefined reference to `sqrt'
collect2: ld 返回 1
这什么意思啊 是不是我编译器问题

追答

如果没有漏掉#include 的话,说明你的编译平台上缺少这个头文件。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-28
代码没问题啊,不过你最前面的/*和后面的*/不是把代码全注释掉了吗?
第2个回答  2012-11-28
好乱 整理下吧
第3个回答  2012-11-28
出现什么问题?追问

未命f 名.c:(.text+0x40): undefined reference to `sqrt'