Advertisement
Guest User

Untitled

a guest
May 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. int a[999]={};
  2. int score,i=0;
  3. while(cin>>score)
  4. {
  5.     if(score<0)  //如果輸入<0視同輸入完畢
  6.     {
  7.         break;
  8.     }
  9.     a[i] = score;
  10.     ++i;       
  11. }
  12. double sum=0;
  13.  
  14. //加總
  15. for(int d=0;d<=i;d++)
  16. {
  17.     sum+=a[d];
  18. }
  19. cout<<"平均值:"<<sum/i<<endl;
  20.  
  21. int temp;
  22. //排序
  23. for(int d=0;d<i-1;d++)
  24. {
  25.     for(int c=0;c<i-1-d;c++)
  26.     {
  27.         if(a[c]>a[c+1])
  28.         {
  29.         temp = a[c];
  30.         a[c]=a[c+1];
  31.         a[c+1]=temp;
  32.         }
  33.     }
  34. }
  35. //a陣列排序完畢
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement