Thu Nov 07 2019

GCD

C++ Programming1094 views

File Name: gcd.cpp

/* Greatest Common Divisor */
#include<iostream>
using namespace std;

void common_divisor(int x, int y) {
	if(y == 0)
		cout << "GCD of two number is: " << x << endl;
	else

		/* Call the common_divisor function inside in it */
		common_divisor(y, x % y);
}


int main() {
	int a, b;
	cout << "Enter two positive number to find Greatest Common Divisor:" << endl;

	/* read two integer from console and store it in "a" and "b" */
	cin >> a >> b;
	common_divisor(a,b);
	return 0;
}


/* Output */
Enter two positive number to find Greatest Common Divisor:
30
20

GCD of two number is: 10

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.