最大公約數gcd

很簡短很有力的函數

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
int gcd(int a,int b);
int main()
{
	int a,b;
	int seq;
	scanf("%d%d", &a, &b);
	printf("%d\n", gcd(a,b));
	system("pause");
	return 0;
}
	
int gcd(int a,int b)
{
    if(b==0) 
    {
        return a;
    }
    else
    { 
        return gcd(b,a%b);
    }
}//gcd 求最大公約數 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章