Sunday, 24 January 2021

lucky number less the in range of natural number n

import java.io.*;
class lucky1
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the range of natural no");
        int n=Integer.parseInt(br.readLine());
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {a[i]=i+1;
        }
        if(n<1)
        {
            System.out.println("invalid number");
        }
            else
            {
                int c=2;
            
                int t=0;
                while(n>=c)
                {
                    for(int i=c-1;i<n;i=i+c)
                     {
                         a[i]=0;
                         
                        }
                        for(int i=0;i<n;i++)
                        {
                            if(a[i]==0)
                            {
                                
                                for(int j=i;j<n-1;j++)
                                {
                                    t=a[j];
                                    a[j]=a[j+1];
                                    a[j+1]=t;
                                }
                                n=n-1;
                            }
                            
                        }
                        
                        c=c+1;
                    }
                        for(int i=0;i<n;i++)
                        {
                            System.out.print(a[i]+",");
                        }
              }
            }
        }

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