fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct student_list {
  5. int id;
  6. int height;
  7. int weight;
  8. }Body;
  9.  
  10.  
  11. int main(void) {
  12. double ave;
  13. double std;
  14. Body data[]={
  15. {1,165,60},{2,170,68},{3,160,50},{4,180,75},{5,175,80}
  16. };
  17. Body a;
  18. for(int i=0;i<4;i++){
  19. for(int j=i+1;j<5;j++){
  20. if(data[i].height>data[j].height){
  21. a=data[i];
  22. data[i]=data[j];
  23. data[j]=a;
  24. }
  25. }
  26.  
  27. }
  28. for(int i=0;i<5;i++){
  29. printf("id:%d,height:%d,weight:%d\n",data[i].id,data[i].height,data[i].weight);
  30. }
  31.  
  32. for(int i=2;i<5;i++){
  33. ave+=data[i].height;
  34. }
  35. ave=ave/3;
  36. double b;
  37. for(int i=2;i<5;i++){
  38. b+=(data[i].height-ave)*(data[i].height-ave);
  39. }
  40. b=b/3;
  41.  
  42. std=sqrt(b);
  43. printf("平均:%.1f,標準偏差:%.1f",ave,std);
  44. return 0;
  45. }
  46.  
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
平均:175.0,標準偏差:4.1