Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void sort(int* sort_a,int num)//sort 函數
- {
- cout<<"sorting...\n";
- for(int i=0;i<num;i++)//排序,如有不懂請找助教
- {
- for(int j=i+1;j<num;j++)
- {
- if(sort_a[i]>sort_a[j])
- {
- int temp;
- temp=sort_a[i];
- sort_a[i]=sort_a[j];
- sort_a[j]=temp;
- }
- }
- }
- }
- int main()
- {
- int n[5];
- cout<<"input 5 numbers:";
- for(int i=0;i<5;i++)
- {
- cin>>n[i];
- }
- //cout<<"n:"<<n<<endl;
- cout<<"n[] before sort: ";
- for(int i=0;i<5;i++)
- {
- cout<<n[i];
- }
- cout<<endl;
- sort(n,5);
- cout<<"after sorted:";
- for(int i=0;i<5;i++)
- {
- cout<<n[i];
- }
- cout<<endl;
- }
Add Comment
Please, Sign In to add comment