fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int a,b,d,e;
  5. int c=1;
  6. scanf("%d",&a);
  7. printf("1つ目の正の整数を入力してください:%d\n",a);
  8. if(a<=0)
  9. printf("正ではありません。\n");
  10. else
  11. {
  12. scanf("%d",&b);
  13. printf("2つ目の正の整数を入力してください:%d\n",b);
  14.  
  15. if(b<=0)
  16. printf("正ではありません。\n");
  17. else
  18. {
  19. do
  20. {
  21. d=a*c;
  22. c=c+1;
  23.  
  24. }
  25. while(d%b!=0);
  26. printf("\n%dと%dの最小公倍数は%dです。\n",a,b,d);
  27. do
  28. {
  29. e=e+1;
  30. }
  31. while((a%e==0)&&(b%e==0));
  32. e=e-1;
  33. printf("%dと%dの最大公約数は%dです。\n",a,b,e);
  34.  
  35.  
  36.  
  37. }
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5300KB
stdin
48
15
stdout
1つ目の正の整数を入力してください:48
2つ目の正の整数を入力してください:15

48と15の最小公倍数は240です。
48と15の最大公約数は1です。