该程序完成按每行5个的格式输出所有3位数中的质数,函数judge用来判断一个整数是否为质数。
程序中存在一些错误,要指出具体出错行的行号并说明出错原因(每行代码后给出的注释内容为行号),请问如何在不改动程序的框架、变量定义的基础上给出正确的程序代码呢?或者说明将出错行做怎样的修改?
下面是问题程序:
#include <stdio.h> //1
#include <math.h> //2
int judge(int n) //3
{ //4
int i, k; //5
k = (int)sqrt(n); //6
for (i = 1; i <= k; i++) //7
if (!n % i ) //8
return 0; //9
else return 1; //10
} //11
int main() //12
{ //13
int count ,i; //14
for (i=101;i<1000;i=i+2) //15
if (judge(i)) //16
{ //17
printf("%5d", i); //18
count++; //19
} //20
if (count % 5 == 0) //21
printf("\n"); //22
return 0; //23
} //24
跑了好多遍,但是就是不对,不知道哪里有问题啊……麻烦各位牛人帮忙看看!
感谢!