求两个数之间的素数及素数之和,可以帮我看看吗,谢谢!
#include<stdio.h>#include<math.h>
#define CORRECT 0
#define FILE_OPEN_ERROR 1
#define FILE_ERROR 2
int main()
{
int t,a,b,n,k,j,sum=0;
FILE * fp = fopen("data.in","r");
if (fp==NULL){
printf("error 1\n");
return 1;
}
t = fscanf(fp,"%d %d",&a,&b);
if( t != 2){
fprintf(stderr,"file empty!\n");
fclose(fp);
return FILE_ERROR;
}
if (a<0 || b<0 || a>b ){
fprintf(stderr,"error 2\n");
fclose(fp);
return 2;
}
for (i = a;i < b; i++){
k =sqrt(i);
for (j = 2; j<=k ;j++);
if (i%j == 0)
break;
if (j>=k){
printf("%-4d",n);:
sum = sum + n;
}
}
printf("%d %d \n",a,b);
printf("%d\n",sum);
return 0;
}
从data.in里读出数据,再计算。 data.in 是与这个文件同目录下的文件,里面有两个数