Showing posts with label GOLD BACH NUMBER. Show all posts
Showing posts with label GOLD BACH NUMBER. Show all posts

Friday, November 1, 2019

ISC COMPUTER SCIENCE QUESTION PRACTICAL PAPER 2018 | QUESTION NUMBER 1 | GOLDBACH NUMBER | Follow on youtube for more |



import java.util.*;
public class qstn_1
{
public static int check(int n,int pos,int input)
{

int result=0;
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
for(int i = pos;i<prime.length;i++)
{
int sum = n+prime[i];
if(sum==input)
{
result= prime[i];
break;
}
sum = 0;
}
return result;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int n = sc.nextInt();
// boundary conditions
if(n<9 || n>50)
{
System.out.println("INVALID INPUT. NUMBER OUT OF RANGE.");
System.exit(0);
}
if(n>1 && n%2!=0)
{
System.out.println("INVALID INPUT. NUMBER IS ODD.");
System.exit(0);
}
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int n1[] = new int[10];
int n2[] = new int[10];
int ins1 = 0,ins2 = 0;
int length = prime.length;
int pos = 0;
int result=0;
int pos2 = 0;
while(length!=0)
{
pos2 = pos;
result = check(prime[pos],pos++,n);
if(result!=0)
{
n1[ins1++] = prime[pos2];// number sending
n2[ins2++] = result; // result from function
}
length--;
}
for(int i=0;i<ins1;i++)
{
System.out.println(n1[i]+", "+n2[i]);
}
}
}

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...