-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathGCD_of_fact_of_two_Numbers.java
More file actions
32 lines (28 loc) · 1.47 KB
/
GCD_of_fact_of_two_Numbers.java
File metadata and controls
32 lines (28 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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"
}
}