返回首页

未知的问题:在C规划的。| 看啊...我必须建立一个规划的读取2个数字,从第一行的文本文件名为:function.in,然后创建一个新的文件名为:function.out写这里面的所有质数里面的两个我得到......这里是一个例子:如果规划的需要1和4,将accually检查2和3
这里是我的代码:

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

int checkprime (int num)

 



{

 int counter = 2;

  while (1)

   {

    if (!(num %  counter)) return 0;

    if ((num/counter) < counter) return counter;

    counter ++;

   }

}

 

int main(){

    FILE *fp;

    int n, m, number, small, big;

    

    fp=fopen("function.in","r");

    fscanf(fp, "%d %d", &n, &m);

    fclose(fp);

    if(n>m)

    {

    small=m;

    big=n;

    }

    else

    {

    small=n;

    big=m;

    }

    

    fp=fopen("function.out","w+");

    for(number=small+1; number<big;>                           if (checkprime (number)){

                                          fprintf(fp,"%d ", number);

                                          }

    }

    fclose(fp);

}


它accually运行得很好......但如果​​最大的是1500或更多的输出是像字形,我不知道为什么......但是,如果它是1000或更少,它是确定的。
请尽快帮我。
谢谢!!| XristosMr:安德烈Kraak

回答