根据题意得如下代码:
#include
#include
#include
int isprime(int x){
/**********Program**********/
int a, b = 1;
for(a=2;aif(x%a==0)
{
b=0;
break;
}
return(b);
/********** End **********/
}
int check(int a,int b,int p[][3]){
/**********Program**********/
int i, j, t;
if (a > b){
t = a;a = b;b = t;
}
t = 0;
for (i = a; i <= b; ++i){
if (i%2 == 0){
t++;
for (j = 2; j <= i/2; ++j){
if (isprime(j) && isprime(i-j)){
p[t-1][0] = i;
p[t-1][1] = j;
p[t-1][2] = i-j;
break;
}
}
}
}
return t;
/********** End **********/
}
int main()
{
int p[100][3],i,k;
FILE *fp;
k=check(4,100,p);
if((fp=fopen("DATA.TXT","w"))==NULL){
printf("File open error\n");
exit(0);
}
for(i=0;iprintf("%4d=%4d+%4d\n",p[i][0],p[i][1],p[i][2]);
fprintf(fp,"%4d=%4d+%4d\n",p[i][0],p[i][1],p[i][2]);
}
fclose(fp);
return 0;
}
int isprime(int x){
/**********Program**********/
int a;
for(a=2;a<=x/2;a++)
if(x%a==0)
{
b=0;
return(0);
}
return(1);