//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "stdlib.h"
int main(void){
int i,j,k,l;
FILE *fp;
if((fp=fopen("b.txt","w"))==NULL){
printf("Open the file failure...\n");
exit(0);
}
for(i=101;i<200;i+=2){
for(j=3;(k=j*j)<=i;j+=2)
if(!(i%j))
break;
if(k>i)
fprintf(fp,++l%5 ? "%d " : "%d\n",i);
}
if(l%5)
fputc('\n',fp);
fclose(fp);
return 0;
}
#include
#include
int prime(int n)
{int i;
for(i=2;i<=sqrt(n);i++)
if(n%i==0)return 0;
return 1;
}
int main()
{FILE *fp;
int i,k=0;
fp=fopen("b.txt","w");
for(i=101;i<200;i+=2)
if(prime(i))
{
fprintf(fp,"%-4d",i);
if(++k%5==0)fprintf(fp,"\n");
}
fclose(fp);
getch();
return 0;
}
运行结果,b.txt文件的内容如下:
101 103 107 109 113
127 131 137 139 149
151 157 163 167 173
179 181 191 193 197
199
耳自己算去,这还编程,拿jsj算去,此类问题不值得编程,望对你有帮助望采纳。