题目:下列程序的功能是:将大于整数m且紧靠m的k个素数存入数组xx。请编写函数nvm(int m,int k,int xx[])实现程序要求,最后调用函数readwriteDAT()把结果输出到out.dat文件中。
#include <conio.h> #include <stdio.h> void readwriteDAT(); int isP(int m) { int i; for(i=2;i<m;i++) if(m%i==0) return 0; return 1; } void num (int m,int k,int xx[]) {int data=m+1; int half,n=0,I; while(1) {half=data/2;for(I=2;I<=half;I++) if(data%I==0)break; if(I>half) {xx[n]=data;n++;} if(n>=k)break; data++; } } main() { int m,n,xx[1000]; clrscr(); printf("\nPlease enter two integers:"); scanf("%d,%d",&m,&n); num(m,n,xx); for(m=0;m<n;m++) printf("%d",xx[m]); printf("\n") readwriteDAT(); } void readwriteDAT() { int m,n,xx[1000],i; FILE *rf,*wf; rf=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0;i<10,i++); fscanf(rf,"%d,%d",&m,&n); num(m,n,xx); for(m=0;m<n;m++) fprintf(wf,"%d",xx[m]); fprintf(wf,"\n"); } fclose(rf) fclose(wf)