fork(1) 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 5288KB
stdin
Standard input is empty
stdout
id 1 :80.000000, 12.247449
id 2 :71.000000, 2.943920
id 3 :81.000000, 16.391054
id 4 :76.000000, 18.448125
id 5 :91.000000, 6.271629