Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions GCD_of_fact_of_two_Numbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Program to find GCD of Factorial of Two Numbers

import java.util.Scanner;

public class GCD_of_fact_of_two_Numbers {
static int factorial(long x)
{
if (x <= 1) //terminating condition
return 1;
int res = 2;
for (int i = 3; i <= x; i++) //calculating factorial of the smaller number
res = res * i;
return res;
}

static int gcdOfFactorial(long m, long n)
{
long min = Math.min(m, n); //checking which number is smaller
return factorial(min); //Method call for the factorial of smaller number
}

/* Driver program to test above functions */
public static void main (String[] args) //main function to initialize variables and call the function
{
long i , j;
Scanner in = new Scanner(System.in);
System.out.print("Enter the values of numbers you want to check : ");
i = in.nextLong() ; //taking inputs from the User say "6" and "8"
j = in.nextLong();
System.out.println("The GCD of numbers "+ i + " and " + j + " is : " + gcdOfFactorial(i, j)); //Method Call with parameter pass as "i" and "j"
}
}
Loading