fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int x, y;
  5.  
  6. printf("2つの整数を入力:\n");
  7. scanf("%d %d", &x, &y);
  8.  
  9. while (x != y) {
  10. if (x > y) {
  11. x = x - y;
  12. } else {
  13. y = y - x;
  14. }
  15. }
  16.  
  17. printf("最大公約数は %d\n", x);
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 5304KB
stdin
10 20
stdout
2つの整数を入力:
最大公約数は 10