[Functions]D. Liang 5.10 Computing GCDc

Description

Compute the greatest common divisor between two positive integers.

Input

Two positive integer n (1 <= n <= 10000) and m (1 <= m <= 10000)

Output

The greatest common divisor between n and m.

Sample Input

35 28

Sample Output

7

Hint

The output is only one line.

//   Date:2020/3/28
//   Author:xiezhg5
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
	int a,b,c,d,temp;
	scanf("%d %d",&a,&b);
    c=a*b;
    if(a<b)
    {
    	temp=a;
    	a=b;
    	b=temp;
    }
    d=b;
    while(d!=0)
    {
    	d=a%b;
    	a=b;
    	b=d;
    }
    printf("%d\n",a);
    return 0;
}
发布了131 篇原创文章 · 获赞 94 · 访问量 2936

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105169512