Friday, 22 January 2021

program of printing prime pairs betwee given no whose sum is equal to the given number

import java.io.*;
class pair
{
    public static void main(String args[])throws IOException
    {   int n=0;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre any number");
        n=Integer.parseInt(br.readLine());
        int c1=0;
        int c=0;
        int t=0;
        int a[]=new int[n];
        if(n%2==0&&n>9&&n<50)
        {
        for(int i=2;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c=c+1;
                }
            }
            if(c==2)
            {
                a[t++]=i;
                c1=c1+1;
            }
            c=0;
        }
        for(int i=0;i<=c1/2;i++)
        {
            int k=a[i];
            for(int j=0;j<=c1;j++)
            {
                if(k+a[j]==n)
                {
                    System.out.print(k+","+a[j]);
                }
            }
            System.out.println();
        }
    }
    else
    System.out.println("given number is odd");
    }
}

No comments:

Post a Comment

HAY THAKYOU FOE VISIT

Program(python):-Find duplicates in an array (Geeks for geek problem)

QUESTION:- Given an array  a  of size  N  which contains elements from  0  to  N-1 , you need to find all the elements occurring more than o...