C语言版
#include<stdio.h> int isPrime(int n) { int j,x; for(j=2;j<n;j++) if(n%j==0) { x=0; break; }else x=1; return x; } int main() { int n,i; printf("Please input a even number(>6):"); scanf("%d",&n); while(n<6||n%2!=0) { printf("Bad number!Please input again:"); scanf("%d",&n); } for(i=3;i<(n/2);i++) { if(isPrime(i)!=0&&isPrime(n-i)!=0) printf("%d=%d+%d\n",n,i,n-i); } }Java语言版
import java.util.Scanner; public class Prime { public int n,i; public int isPrime(int n) { int j, x = 0; for (j = 2; j < n; j++) if (n % j == 0) { x = 0; break; } else x = 1; return x; } public static void main(String[] args) { Prime num =new Prime(); System.out.printf("Please input a even number(>6):"); Scanner input1 = new Scanner(System.in); int n = input1.nextInt(); while (n < 6 || n % 2 != 0) { System.out.printf("Bad number!Please input again:"); n = input1.nextInt(); } for (int i = 3; i < (n / 2); i++) { if (num.isPrime(i)!= 0 && num.isPrime(n - i) != 0) System.out.println(n + "=" + i + "+" + (n - i)); } } }