fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct
  5. {
  6. int id;
  7. double height;
  8. double weight;
  9. }Body;
  10.  
  11.  
  12. int main(void) {
  13.  
  14. int i,j;
  15. double sum=0.0,ave,std;
  16.  
  17. Body data[]={
  18. {1,165,60},
  19. {2,170,68},
  20. {3,160,50},
  21. {4,180,75},
  22. {5,175,80},
  23. };
  24.  
  25. for(i=0;i<4;i++)
  26. {
  27. for(j=0;j<4-i;j++)
  28. {
  29. if(data[j].height>data[j+1].height)
  30. {
  31. Body temp=data[j];
  32. data[j]=data[j+1];
  33. data[j+1]=temp;
  34. }
  35. }
  36. }
  37. for(i=2;i<5;i++)
  38. {
  39. sum+=data[i].height;
  40. }
  41. ave=sum/3.0;
  42.  
  43. double goukei=0.0;
  44. for(i=2;i<5;i++)
  45. {
  46. goukei+=(ave-data[i].height)*(ave-data[i].height);
  47. }
  48. std=sqrt(goukei/3.0);
  49.  
  50. for (int i=0;i<5;i++)
  51. {
  52. printf("ID:%d 身長:%.1f 体重:%.1f\n",data[i].id, data[i].height, data[i].weight);
  53. }
  54.  
  55. printf("平均:%.1f\n",ave);
  56. printf("標準偏差:%.1f",std);
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
ID:3 身長:160.0 体重:50.0
ID:1 身長:165.0 体重:60.0
ID:2 身長:170.0 体重:68.0
ID:5 身長:175.0 体重:80.0
ID:4 身長:180.0 体重:75.0
平均:175.0
標準偏差:4.1