fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int arr[5] = {3, 1, 8, 5, 2};
  5. int max, min, diff;
  6.  
  7. max = arr[0];
  8. min = arr[0];
  9.  
  10. for (int i = 1; i < 5; i++) {
  11. if (arr[i] > max) {
  12. max = arr[i];
  13. }
  14. if (arr[i] < min) {
  15. min = arr[i];
  16. }
  17. }
  18.  
  19. diff = max - min;
  20.  
  21. printf("最大値: %d\n", max);
  22. printf("最小値: %d\n", min);
  23. printf("最大値と最小値の差: %d\n", diff);
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5276KB
stdin
 
stdout
最大値: 8
最小値: 1
最大値と最小値の差: 7