fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define STUDENTS 5
  4. #define EXAMS 3
  5.  
  6. typedef struct {
  7. int id;
  8. int math;
  9. int english;
  10. int physics;
  11. double ave;
  12. double std;
  13. }Grades;
  14.  
  15. int main(void)
  16. {
  17. Grades data[]={{1,65,80,95},{2,70,68,75},{3,60,100,83},{4,100,55,74},{5,90,85,100}};
  18. for(int i=0;i<STUDENTS;i++)
  19. {
  20. data[i].ave=(data[i].math+data[i].english+data[i].physics)/EXAMS;
  21. data[i].std=sqrt(((data[i].math-data[i].ave)*(data[i].math-data[i].ave)+(data[i].english-data[i].ave)*(data[i].english-data[i].ave)+(data[i].physics-data[i].ave)*(data[i].physics-data[i].ave))/EXAMS);
  22. printf("id %d :%.1f, %.1f\n",data[i].id,data[i].ave,data[i].std);
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
id 1 :80.0, 12.2
id 2 :71.0, 2.9
id 3 :81.0, 16.4
id 4 :76.0, 18.4
id 5 :91.0, 6.3