WAP to enter a number 'N' and check whether it is a "GoldBach" Number or not. if yes, then also print the pairs of odd prime number pairs of whcich 'N' is a sum.
A GoldBach Number is an even number which can be expresed as sum of two odd primes.
Example:
INPUT: 30
OUTPUT:
GoldBach Number
7,23
11,19
13,17
import java.util.Scanner;
public class GOLDBACH
{
public static void main(String [] args) {
int N,c=0,d=0,r,s=0,f=0;
System.out.println("ENTER A NUMBER");
N = new Scanner(System.in).nextInt();
if(N%2==0) {
for(int i=3;i<=N/2;++i) {
s=c=d=0;
for(int j=1;j<=i;++j) {
if(i%j==0)
++c;
}
if(c==2)
s=N-i;
for(int j=1;j<=s;++j) {
if(s%j==0)
++d;
}
if(d==2) {
System.out.println(i+", "+s);
}
}
}
else
System.out.println("NOT GOLD BACH NUMBER");
}
}
by,
ANUBRATA DAS