/*欧几里德算法:辗转求余
  原理: gcd(a,b)=gcd(b,a mod b)
  当b为0时,两数的最大公约数即为a

  getchar()会接受前一个scanf的回车符
*/

#include<stdio.h>

void main()
{
    int temp;
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    printf("the greatest common factor of %d and %d is ",a,b);
    while(b!=0)
    {
        temp=b;
        b=a%b;
        a=temp;
    }
    printf("%d\n",a);
    getchar();
    getchar();
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-05-02
  • 2022-01-27
  • 2022-12-23
  • 2021-11-24
  • 2022-01-30
猜你喜欢
  • 2022-01-07
  • 2021-07-04
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
相关资源
相似解决方案