diff --git a/SOLUTIONS/GCD.java b/SOLUTIONS/GCD.java new file mode 100644 index 00000000..05ab0218 --- /dev/null +++ b/SOLUTIONS/GCD.java @@ -0,0 +1,37 @@ +/* package codechef; // don't place package name! */ + +import java.util.*; +import java.lang.*; +import java.io.*; + +/* Name of the class has to be "Main" only if the class is public. */ +class Codechef +{ + static int gcd(int a, int b) + { + if (a == 0) + return b; + return gcd(b % a, a); + } + static int findGCD(int arr[], int n) + { + int result = arr[0]; + for (int i = 1; i < n; i++) + result = gcd(arr[i], result); + return result; + } + + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int arr[] = new int[n]; + for(int i=0;i