Page 603 - Computer science 868 Class 12
P. 603
Program 15 A Goldbach number is a positive even integer that can be expressed as the sum of two odd
primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6 = 3 + 3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e., 3 and 7,
5 and 5.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the odd prime
pairs whose sum is equal to the number 'N'.
1 import java.util.*;
2 class GoldBatch
3 { int n;
4 GoldBatch(int nn)
5 { n=nn;}
6 int isPrime(int a)
7 { int c=0;
8 for(int i=1;i<=a;i++)
9 { if(a%i==0)
10 c++;
11 }
12 return c;
13 }
14 void check()
15 { int r1,r2,i,j;
16 if(n<=9 || n>=50 )
17 System.out.println("INVALID INPUT NUMBER OUT OF RANGE");
18 else if(n%2!=0)
19 System.out.println("INVALID INPUT NUMBER IS ODD ");
20 else
21 { System.out.println("Sum of prime numbers are");
22 for(i=3;i<=n;i=i+2)
23 { r1=isPrime(i);
24 for(j=i;j<=n;j=j+2)
601
Internal Assessment 601

