fork(1) download
  1. #include <stdio.h>
  2. #include <math.h>
  3. typedef struct {
  4. int id;
  5. int height;
  6. int weight;
  7. } Body;
  8.  
  9. int main(void) {
  10. Body data[] = {
  11. {1, 165, 60},
  12. {2, 170, 68},
  13. {3, 160, 50},
  14. {4, 180, 75},
  15. {5, 175, 80}
  16. };
  17. for (int i = 0; i < 4; i++) {
  18. for (int j = 0; j < 4-i; j++) {
  19. if (data[j].height > data[j+1].height) {
  20. Body temp = data[j];
  21. data[j] = data[j+1];
  22. data[j+1] = temp;
  23. }
  24. }
  25. }
  26. for(int i=0;i<5;i++){
  27. printf("id:%d\n",data[i].id);
  28. printf("height:%d\n",data[i].height);
  29. printf("weight:%d\n",data[i].weight);
  30. }
  31. double sum=0.0,ave,std=0.0;
  32. for (int i=2;i<5;i++) {
  33. sum += data[i].height;
  34. }
  35. ave=sum/3.0;
  36.  
  37. for (int i=2; i<5; i++) {
  38. std +=(data[i].height-ave)*(data[i].height-ave);
  39. }
  40. std = sqrt(std / 3.0);
  41. printf("\n身長が高い3名の平均身長: %.1f \n", ave);
  42. printf("標準偏差: %.1f \n", std);
  43. return 0;
  44. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
id:3
height:160
weight:50
id:1
height:165
weight:60
id:2
height:170
weight:68
id:5
height:175
weight:80
id:4
height:180
weight:75

身長が高い3名の平均身長: 175.0 
標準偏差: 4.1