1. 程式人生 > >用冒泡法對10個數排序

用冒泡法對10個數排序

inpu sort cout log pac ted 個數 names std

#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; }

技術分享

用冒泡法對10個數排序