fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. double heikin(int a[]);
  5. int goukaku(int a[],int b);
  6. void hensachi(int data[],double dev[],double ave);
  7.  
  8. int main(void)
  9. {
  10. int data[5],i;
  11. double ave;
  12. double deviation[5];
  13. for (i=0;i<=4;i++)
  14. {
  15. printf("data[%d]= \n",i);
  16. scanf("%d",&data[i]);
  17. }
  18. ave=heikin(data);
  19. printf("heikin=%f \n",ave);
  20. printf("goukaku=%d\n",goukaku(data,5));
  21. hensachi(data,deviation,ave);
  22. for (i=0;i<=4;i++)
  23. {
  24. printf("deviation[%d]=%f\n",i,deviation[i]);
  25. }
  26. return 0;
  27. }
  28.  
  29. double heikin(int a[])
  30. {
  31. int i,k=0;
  32. for(i=0;i<=4;i++)
  33. {
  34. k=k+a[i];
  35. }
  36. return((double)k/5);
  37. }
  38.  
  39. int goukaku(int a[], int b)
  40. {
  41. int n=0;
  42. for(;b!=0;--b)
  43. if(a[b-1] >= 6)
  44. ++n;
  45. return n;
  46. }
  47.  
  48. void hensachi(int data[],double dev[],double ave)
  49. {
  50. int i;
  51. double stddev,d=0;
  52.  
  53. for (i=0;i<=4;i++)
  54. {
  55. d+=pow(data[i]-ave,2);
  56. }
  57. stddev=pow(d/5,0.5);
  58. printf("Standard Deviation=%f\n",stddev);
  59. for (i=0;i<=4;i++)
  60. {
  61. dev[i]=10*(data[i]-ave)/stddev+50;
  62. }
  63. }
  64.  
Success #stdin #stdout 0.01s 1724KB
stdin
3
4
5
6
7
stdout
data[0]= 
data[1]= 
data[2]= 
data[3]= 
data[4]= 
heikin=5.000000 
goukaku=2
Standard Deviation=1.414214
deviation[0]=35.857864
deviation[1]=42.928932
deviation[2]=50.000000
deviation[3]=57.071068
deviation[4]=64.142136