新手求教 验证哥德巴赫猜想
任何一个大于6的偶数均可表示为两个素数之和。要求将6到100之间的偶数都表示成两个素数之和,打印时一行打印5组。 请高手指点,谢~~~
#include <stdio.h> int get_pm(int[]); int main(void) { int number[100]={2,3,5}; int count = 0; int i = 0; int j = 0; int result = 6; int hang = 0; count = get_pm(number); /*用所有索数将六到一百以内的偶数相加*/ for(i = 0;i<count;i++) { for(j=0;j<count;j++) if(number[i]+number[j] == result) { if(result >100) { printf("\n\n"); return 0; } if((hang%5) == 0) printf("\n"); printf("%d+%d == %d ",number[i],number[j],result); i = j = 0; hang++; result += 2; } } return 0; } int get_pm(int number[]) { int count = 50; int i = 3; int value = 7; int j = 0; char is_pm = 'y'; while(--count) { for(j=0;j<i;j++) if((value%number[j]) == 0) { is_pm = 'n'; break; } if(is_pm == 'y') number[i++] = value; is_pm = 'y'; value += 2; } return i; }