编程计算两个正整数的最大公约数。在主函数中编程调用函数,输出最大公约数。
程序的运行示例:
12,3↙
3
####函数原型说明
求最大公约数的函数原型如下:
int MaxCommonFactor( int a, int b);
返回值:返回的是最大公约数;若输入的数据有任意一个不满足条件,返回值是-1。 参数:a,b是两个整型数
#includeint MaxCommonFactor( int a, int b) { int c; if(a<=0||b<=0) return -1; while(b!=0) { c=a%b; a=b; b=c; } return a; } int main(void) { int a,b,c; scanf("%d,%d",&a,&b); int MaxCommonFactor( int a, int b); c=MaxCommonFactor(a,b); printf("%dn",c); return 0; }



