Coders Packet

Prominal Number in java

By Sushma Kumari

The primorial number is multiplication of the all prime numbers also which is the analog of the usual factorial for prime numbers.The Java code is compiled and run on a Windows 10 in BlueJ.exe.

Write a Program in Java to print factorial of prime numbers of all primorial numbers.

//To print factorial of prime numbers.

Primorial Number is most important in our mathematics or computer languages. It is a type of number which simplifies the number in an easy way or system like when we multiply any kind of number etc. It is also the product of all prime numbers.
Eg:
4=1×2×3=6
5=1×2×3×5=30

Source Code:

Write a Program in Java to print factorial of prime numbers of all primorial numbers.
import java.io.*;
public class primorial
{
    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n,prod=1,i,c=0,j;
        System.out.println("enter a no");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c=c+1;
                }
            }
            if(c==2)
            prod=prod*i;
            c=0;
        }
        System.out.println(prod);
    }
}

Outputs:

Input-6

Output-30

6=2×3×5

 

Download Complete Code

Comments

No comments yet