Skip to content

Commit c8a368d

Browse files
authored
Merge pull request #117 from itsEobard2025/new-branch
Added a Java File to find GCD of Factorial of Two Numbers
2 parents 7abc536 + 360294e commit c8a368d

File tree

2 files changed

+1786
-0
lines changed

2 files changed

+1786
-0
lines changed

GCD_of_fact_of_two_Numbers.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Program to find GCD of Factorial of Two Numbers
2+
3+
import java.util.Scanner;
4+
5+
public class GCD_of_fact_of_two_Numbers {
6+
static int factorial(long x)
7+
{
8+
if (x <= 1) //terminating condition
9+
return 1;
10+
int res = 2;
11+
for (int i = 3; i <= x; i++) //calculating factorial of the smaller number
12+
res = res * i;
13+
return res;
14+
}
15+
16+
static int gcdOfFactorial(long m, long n)
17+
{
18+
long min = Math.min(m, n); //checking which number is smaller
19+
return factorial(min); //Method call for the factorial of smaller number
20+
}
21+
22+
/* Driver program to test above functions */
23+
public static void main (String[] args) //main function to initialize variables and call the function
24+
{
25+
long i , j;
26+
Scanner in = new Scanner(System.in);
27+
System.out.print("Enter the values of numbers you want to check : ");
28+
i = in.nextLong() ; //taking inputs from the User say "6" and "8"
29+
j = in.nextLong();
30+
System.out.println("The GCD of numbers "+ i + " and " + j + " is : " + gcdOfFactorial(i, j)); //Method Call with parameter pass as "i" and "j"
31+
}
32+
}

0 commit comments

Comments
 (0)