#include
int main(void)
{
int N,A,B,i,X,j,count_a=0,count_b=0,k,flag_a=0,flag_b=0; //A表示离相应测试数据最近的素数,B表示测试数据与A之间的距离
printf("请输入需要测试的数据组数: ");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
printf("请输入测试数据: ");
scanf("%d",&X);
for(j=X;j>1;j--) //向A的左侧寻找素数
{
for(i=2;i<j;i++)
{
if(j%i==0) {if(j<X) count_a++;break;}
if((i==(j-1))&&(j%i!=0)){flag_a=1; count_a++;break;}
}
if(flag_a==1) break;
}
for(k=X;;k++) //向A的右侧寻找素数
{
for(i=2;i<k;i++)
{
if(k%i==0) {if(k>X) count_b++;break;}
if((i==(k-1))&&(k%i!=0)) {flag_b=1;count_b++;break;}
}
if(flag_b==1) break;
}
if(count_a==count_b) {B=count_a;A=j;printf("%d,%d a\n",A,B);}
else if((j==X)&&(k==X)) {B=0;A=X;printf("%d,%d b\n",A,B);}
else if(count_a>count_b) {B=count_b;A=k;printf("%d %d c\n",A,B);}
else if(count_a<count_b) {B=count_a;A=j;printf("%d %d d\n",A,B);}
}
}
这个程序无论N等于几,都只能输入一组测试数据,为什么最外侧for循环不运行??求解!!