Tuesday, 3 August 2021

program to take input of number of rows and coloum of a metrix and print the prime number coloum wise

import java.io.*;
class Primes
{
    int r;
    int c;
     int Arr[][]=new int [20][20];
    Primes(int x,int y)
    {
        r=x;
        c=y;
   
     for(int i=0;i<r;i++)
     {
         for(int j=0;j<c;j++)
         {
             Arr[i][j]=0;
            }}
      
    }
    int isprime(int q)
    {
        int c=0;
        for(int i=1;i<=q;i++)
        {
            if(q%i==0)
            {
                c=c+1;
            }
        }
            if(c==2)
            return 1;
            else
            return 0;
        
    }
     void fill()
    {
        int k=2;
          for(int i=0;i<r;i++)
          {
              for(int j=0;j<c;j++)
              {
                 while(isprime(k)!=1)
                    {
                        k=k+1;
                      
                    }
                    Arr[i][j]=k;
                    k=k+1;
                }
            }
        }
   
void display()
{
    for(int i=0;i<c;i++)
    {
        for(int j=0;j<r;j++)
        {
            System.out.print(Arr[j][i]+"\t");
        }
        System.out.println();
    }
}
public static void main(String args[])throws IOException
{
    
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter row and coloumn \t");
    int a=Integer.parseInt(sc.readLine());
    int b=Integer.parseInt(sc.readLine());
    Primes ob1=new Primes(a,b);
  ob1.fill();
    ob1.display();
}
}
    
 

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...