#include#includevoidmain(){intprime(int);voidf(intx);intn,m;printf("\nInputaninteger:");scanf("%d",&n);if(prime(n))printf("\n%disaprime.\n",n);elseprintf...
#include
#include
void main()
{
int prime(int);
void f(int x);
int n,m;
printf("\nInput an integer:");
scanf("%d",&n);
if(prime(n))
printf("\n%d is a prime.\n",n);
else
printf("\n %d is not a prime.\n",n);
printf("Please input a even number(>=6):\n");
scanf("%d",&m);
while(m%2!=0)
{printf("Please input a even number");
scanf("%d",&m);
}
printf("%d=",m);
f(m);
}
int prime(int n)
{int flag=1,i;
for(i=2;i<=n/2&&flag==1;i++)
if(n%i==0)
flag=0;
return (flag);
}
void f(int x)
{ int p,q,i,fp,fq;
p=1;
do
{p=p+1,q=x-p;
fp=1;
for(i=2;i<=sqrt(p);i++) //为什么这里要用sqrt函数
if(p%i==0)
{fp=0;break;}
fq=1;
for(i=2;i
if(q%i==0){fq=0;break;}
}
while((fp==0)||(fq==0)); //这里让fq==0和fp==0 有什么用?
printf("%d+%d",p,q);
}
展开