求最大公约数函数版

来源:互联网 发布:百度知道软件下载 编辑:程序博客网 时间:2024/06/06 04:09

刚学完函数把原来的程序稍改了一下

#include <stdio.h>int gcd (int a,int b){int g,y=1;while (y!=0)  {          y=a%b;          a=b;          b=y;                  }  return (a);}main(){int c,d,out;scanf("%d,%d",&c,&d);out=gcd(c,d);printf("最大公约数为%d\n",out);}