求两个数的最大公约数

来源:互联网 发布:类似于快刀的软件 编辑:程序博客网 时间:2024/06/05 16:30
#include <stdio.h>int main(){    int x = 0;int y = 0;int num1, num2, temp;      printf("请输入两个正整数:\n");      scanf("%d %d", &num1, &num2);      if(num1 < num2)      {          temp = num1;          num1 = num2;          num2 = temp;      }    x = num1;      y = num2;      while(y != 0)    {  //辗转相除法        temp = x%y;          x = y;          y = temp;      }      printf("它们的最大公约数为:%d\n", x);        return 0;  }  

1 0
原创粉丝点击