C语言编程之偶数分解为两个素数之和

版权声明:此篇博文为博主心血o(╥﹏╥)o,如要转载请注明来源,勿忘心安! https://blog.csdn.net/dyq1995/article/details/88413680

问题描述:偶数总能表示为两个素数之和,使用C语言编程实现。

程序源码:

#include "stdio.h"
#include "math.h"
void main()
{ 
int a,b,c,d;
scanf("%d",&a);
for(b=3;b<=a/2;b+=2)
{ for(c=2;c<=sqrt(b);c++)
if(b%c==0) break;
if(c>sqrt(b))
d=a-b;
else
break;
for(c=2;c<=sqrt(d);c++)
if(d%c==0) break;
if(c>sqrt(d))
printf("%d=%d+%d\n",a,b,d);
}
}

猜你喜欢

转载自blog.csdn.net/dyq1995/article/details/88413680