当前位置:网站首页>Exercise: find the greatest common divisor of two numbers by recursion

Exercise: find the greatest common divisor of two numbers by recursion

2021-07-28 02:41:04 Life code_ official account

#include<stdio.h>
int Gcd(int, int);
int main(void)
{
	int m,n;
	printf(" Please enter  m,n  Value :");
	scanf("%d%d", &m, &n);
	printf("%d and %d The greatest common divisor of is %d\n", m, n, Gcd(m,n));
	return 0;
}

int Gcd(int m, int n)
{
	if(m % n == 0)
	{
		return n;
	}
	else 
	{
		return Gcd(n, m%n);
	}
}

 Insert picture description here

版权声明
本文为[Life code_ official account]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/07/20210718163023062r.html

随机推荐