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. Grades data[]={
  17. {1,65,80,95},
  18. {2,70,68,75},
  19. {3,60,100,83},
  20. {4,100,55,74},
  21. {5,90,85,100}};
  22.  
  23. for (int i=0; i<STUDENTS; i++){
  24. data[i].ave=(data[i].math + data[i].english + data[i].physics) / EXAMS;
  25. 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;
  26. printf("id %d : ave %lf : std %lf\n",data[i].id,data[i].ave,data[i].std);
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
id 1 : ave 80.000000 : std 7.071068
id 2 : ave 71.000000 : std 1.699673
id 3 : ave 81.000000 : std 9.463380
id 4 : ave 76.000000 : std 10.651030
id 5 : ave 91.000000 : std 3.620927