47-題目1056:最大公約數

http://ac.jobdu.com/problem.php?pid=1056

題目描述:

輸入兩個正整數,求其最大公約數。

題目比較簡單

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	int A,B,temp,max;
	ifstream cin("data.txt");
	while (cin >> A >> B)
	{
		temp = A > B ? B : A;  //取A,B中的較小值
		for (int i = 1; i <= temp; i++)
			if (A % i == 0 && B % i == 0)
				max = i;
		cout << max << endl;	
	}//end of while
	system("pause");
	return 0;
}


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