fork(2) download
  1. #include<iostream>//計算平均、中位數、眾數
  2. using namespace std;
  3. void average(double answer[] ,int as) ;
  4. void sort(double answer[],int as);
  5. void median(double answer[],int as);
  6. void m(int x,int y) ;
  7. int main()
  8. {
  9. const int size=10;
  10. double a[10]={1,2,10,4,8,7,6,5,9,3};
  11. average(a,10);
  12. median(a,10);
  13. cout<<"在main裡的a"<<endl;
  14. for(int i=0;i<10;i++)
  15. cout<<a[i]<<"\t";
  16. cout<<endl;
  17. int c,d;
  18. c=100;d=101;
  19. m(100,101);
  20. cout<<c;
  21. }
  22. void average(double answer[],int as)
  23. {
  24. double x=0;
  25. for(int i=0;i<=as;i++)
  26. x=x+answer[i];
  27. cout<<x/as<<endl;
  28. }
  29. void median(double answer[],int as)
  30. {
  31. sort(answer,10);
  32. }
  33. void sort(double answer[],int as)
  34. {
  35. int temp;
  36. for(int i=0;i<as;i++)
  37. {
  38. for(int j=0;j<as-1;j++)
  39. if(answer[j]>answer[j+1])
  40. {
  41. temp=answer[j];
  42. answer[j]=answer[j+1];
  43. answer[j+1]=temp;
  44. }
  45. }
  46. cout<<"利用sort 結果"<<endl;
  47. for(int i=0;i<as;i++)
  48. {
  49. cout<<answer[i]<<"\t";
  50. }
  51. cout<<endl;
  52. }
  53. void m(int x,int y)
  54. {
  55. x=x+y;
  56. cout<<x<<endl;
  57. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
-1.20412e+306
利用sort 結果
1	2	3	4	5	6	7	8	9	10	
在main裡的a
1	2	3	4	5	6	7	8	9	10	
201
100