top of page
Writer's pictureSatyam Gupta

Primorial Number in JAVA

Updated: Apr 30, 2019

Primorial Number is like factorial number.

In Primorial Number all the prime numbers upto a given number is Multiplied.


Example : Input = 10

              Output = 210

Primorial : 2*3*5*7


 

Algorithm and Program Below :-

Algorithm :-

  • Input a Number

  • check for all the prime numbers till the entered number

  • Multiply all the prime numbers in a new variable

  • Print Input Number and Primorial Number

 

Program :-

import java.io.*; import java.util.*; class Primorial {     public static void main(String args[])     {         Scanner in= new Scanner(System.in);         int c=0,s=1;         int n,i,j,p;         System.out.print("Enter Number: ");         n= in.nextInt(); // Input a Number         p=n; // copy of input number         for(i=1;i<=n;i++)         {             for(j=1;j<=i;j++)             {                 if(i%j==0) // checking prime number                 {                     c++;                 }             }             if(c==2)             {                 s=s*i; // Multiplying Prime numbers             }             c=0; // Initializing c=0 to check for next prime number         }         System.out.println("Original Number : "+p);         System.out.println("Primorial Number : "+s);     } // end of main } // end of class

 

Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.


All the best :)

Keep Learning :)

458 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page