第4週目の項目1-4個の数の最大公約数を求めます

989 ワード

/*
*Copyright(C) 2016,          
*All rights reserved.
*   :test.cpp
*  :   
*    :2016 3 23 
*   :v1.0
*
*    :           
*/
#include<iostream>
using namespace std;
int gcd(int a,int b);
int gcds(int x,int y,int a,int w);
int main()
{
	int a,b,d,e,g;
	cin>>a>>b>>d>>e;
	g=gcds(a,b,d,e);
	cout<<"      :"<<g;
	return 0;
}
int gcds(int x,int y,int a,int w)
{
    int i,j,m;
    i=gcd(x,y);
    j=gcd(a,w);
    m=gcd(i,j);
    return m;
}
int gcd(int a,int b)
{
    int r;
    while(a!=0)
    {
        r=a%b;
        b=a;
        a=r;
    }
    return b;
}
<img src="http://img.blog.csdn.net/20160323185453502?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
     :