用冒泡法對10個數排序


#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
    int a[11];
    int i, j, t;

    cout<<"input 10 nummbers:"<<endl;
    for(i=1;i<11;i++)
        {
            cin>>a[i];
        }

    cout<<endl;

    for(j=1;j<11;j++)
        {
            for(i=1;i<=10-j;i++)
                {
                    if(a[i]>a[i+1])
                        {
                            t = a[i];
                            a[i] = a[i+1];
                            a[i+1] = t;

                        }
                }
        }
    cout<<"the sorted nummbers:"<<endl;
    for(i=1;i<11;i++)
        {
            cout<<a[i]<<" ";
        }

    cout<<endl;
    system("pause");
    return 0;
}


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM