Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 函數:計算最大公因數
- int gcd(int num1, int num2);
- int main()
- {
- int num1, num2;
- cin >> num1 >> num2;
- cout << gcd(num1, num2) << endl;
- return 0;
- }
- // 實現 gcd 函數
- int gcd(int num1, int num2)
- {
- while (num2 != 0)
- {
- int temp = num2;
- num2 = num1 % num2;
- num1 = temp;
- }
- return a; // 返回計算結果
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement