fork download
  1. #include <stdio.h>
  2.  
  3. int gcd(int a, int b) {
  4. int temp;
  5. while (b != 0) {
  6. temp = b;
  7. b = a % b;
  8. a = temp;
  9. }
  10. return a;
  11. }
  12.  
  13. int main() {
  14. int num1, num2;
  15. printf("2つの整数を入力してください: ");
  16. scanf("%d %d", &num1, &num2);
  17.  
  18. int result = gcd(num1, num2);
  19. printf("最大公約数は: %d\n", result);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
2つの整数を入力してください: 最大公約数は: 2