2015年2月3日22:36:09
1.请在4~100内验证哥德巴赫猜想,输出每一个偶数的所有可能的拆分方法。例如:
4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7 = 5 + 5
12 = 5 + 7
14 = 3 + 11 = 7 + 7
……
#include <stdio.h>
#include <stdlib.h>
int main()
{
int iNum,iTest,iFirst,iSecond,bFirst,bSecond;
for(iNum = 4;iNum <= 100;iNum += 2)
{
printf("%d",iNum);
for(iFirst = 2;iFirst <= iNum/2;iFirst++)
{
//Decide first
bFirst = 0;
for(iTest = 2;iTest < iFirst;iTest++)
{
if(0 == iFirst%iTest)
{
bFirst = 1;
break;
}
}
if(0 == bFirst)
{
iSecond = iNum - iFirst;
bSecond = 0;
for(iTest = 2;iTest < iSecond;iTest++)
{
if(0 == iSecond%iTest)
{
bSecond = 1;
break;
}
}
if(0 == bSecond)
{
printf("=%d+%d",iFirst,iSecond);
}
}
}
printf("\r\n");
}
system("pause");
return 0;
}