使用递归求最大公约数
#include <stdio.h> int Gcd(int a, int b) { if(a==b) return a; if(a>b) return Gcd(a-b,b); if(a<b) return Gcd(a,b-a); } int main() { printf("Input a,b:"); int a,b; scanf("%d,%d",&a,&b); if(a<=0||b<=0) { printf("Input number should be positive!\n"); return 0; } else { printf("Greatest Common Divisor of %d and %d is %d\n",a,b,Gcd(a,b)); } return 0; }