Advertisement
junsangtutor

zerojudge a024 without struct

Dec 2nd, 2023 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // 函數:計算最大公因數
  5. int gcd(int num1, int num2);
  6.  
  7. int main()
  8. {
  9.     int num1, num2;
  10.     cin >> num1 >> num2;
  11.  
  12.     cout  << gcd(num1, num2) << endl;
  13.  
  14.     return 0;
  15. }
  16.  
  17. // 實現 gcd 函數
  18. int gcd(int num1, int num2)
  19. {
  20.     while (num2 != 0)
  21.     {
  22.         int temp = num2;
  23.         num2 = num1 % num2;
  24.         num1 = temp;
  25.     }
  26.     return a;  // 返回計算結果
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement