#include<stdio.h>#include<stdlib.h>intmain(){int a,b,r;//r最初为余数scanf("%d %d",&a,&b);if(b==0){printf("gcd is %d\n");return0;}for(r=a%b;r!=0;r=a%b){
a=b;
b=r;}printf("gcd is %d\n",b<0?-b:b);return0;}
辗转相除法求两数的最大公约数输入用空格连接的两个整数,求这两个数的最大公约数。#include <stdio.h>#include <stdlib.h>int main(){ int a,b,r; //r最初为余数 scanf("%d %d",&a,&b); if (b==0) { printf("gcd is %d\n"); return 0; } for