Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a[999]={};
- int score,i=0;
- while(cin>>score)
- {
- if(score<0) //如果輸入<0視同輸入完畢
- {
- break;
- }
- a[i] = score;
- ++i;
- }
- double sum=0;
- //加總
- for(int d=0;d<=i;d++)
- {
- sum+=a[d];
- }
- cout<<"平均值:"<<sum/i<<endl;
- int temp;
- //排序
- for(int d=0;d<i-1;d++)
- {
- for(int c=0;c<i-1-d;c++)
- {
- if(a[c]>a[c+1])
- {
- temp = a[c];
- a[c]=a[c+1];
- a[c+1]=temp;
- }
- }
- }
- //a陣列排序完畢
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement