Check out example codes for "maximo comun divisor". It will help you in understanding the concepts better.

Code Example 1

int mcd(int a, int b){
	if(a == b){
		return a;
	}
	else{
		if(a > b){
			return mcd(a - b, b);
		}
		else{
			return mcd(a, b - a);
		}
	}
}

Code Example 2

// calcula el maximo comun divisor
	int mcd(int a, int b){
    int max;

    if(b == 0){
      max = a;
    }else{
      max = mcd(b, a % b);
    }

    return max;
	}

Learn ReactJs, React Native from akashmittal.com