fork download
  1. #include <stdio.h>
  2.  
  3. //関数のプロトタイプ宣言
  4. int max(int x, int y);
  5.  
  6. int main(void) {
  7. int a, b, c, d;
  8. int max_value;
  9.  
  10. // 4つの値を入力
  11. printf("4つの整数を入力してください: ");
  12. scanf("%d %d %d %d", &a, &b, &c, &d);
  13.  
  14. // maxの入れ子構造を利用
  15. max_value = max(max(a, b), max(c, d));
  16.  
  17. printf("最大値 = %d\n", max_value);
  18.  
  19. return 0;
  20. }
  21.  
  22. //max関数の定義
  23. int max(int x, int y) {
  24. return (x > y) ? x : y;
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
Success #stdin #stdout 0s 5312KB
stdin
2 3 4 5
stdout
4つの整数を入力してください: 最大値 = 5