Fri Jun 08 2018

GCD

C Programming997 views

File Name: gcd.c

#include<stdio.h>

void common_divisor(int, int);

int main() {
	int a, b;
	printf("Enter two positive number to find Greatest Common Divisor:\n");
	scanf("%d %d",&a, &b);
	common_divisor(a,b);
	return 0;
}

/* Recursive function */
void common_divisor(int x, int y) {
	if(y == 0)
		printf("GCD of two number is: %d\n",x);
	else
		/* Call the common_divisor function inside in it */
		common_divisor(y, x % y);
}



/* 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.