By using this, you can pass multiple values as well in the form of array:- // pass all the values in array and call findGCD function int findGCD(int arr[], int n) { int gcd = arr[0]; for (int i = 1; i < n; i++) { gcd = getGcd(arr[i], gcd); } return gcd; } // check for gcd int getGcd(int x, int y) { if (x == 0) return y; return gcd(y % x, x); }