输入一组数字,找出其排列的最小值

#include <iostream>

using namespace std;

void bubblesort(int a[], int x) {
    int y, z;
    for (y = 0; y <= x - 1; y++) {
        for (z = 0; z<x - 1 - y; z++) {
            if (a[z]>a[z + 1])
                swap(a[z], a[z + 1]);
        }
    }
};

void swap(int &x, int &y) {
    int tamp;
    tamp = x;
    x = y;
    y = tamp;
};

int main()
{
    int a[20] = { 0 };
    int i, j = 0, num = 0, k;
    cout << "Please enter the numbers:";
    cin >> a[j];
    j++;
    while (j < 10) {
        cin >> a[j];
        j++;
    }

    bubblesort(a, j);
    while (a[num] == 0) {
        num=num+1;
    }
    cout << a[num];
    for (k = 0; k < num; k++) {
        cout << "0";
    }
    while (num+1<j) {
        num++;
        cout << a[num];
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42082542/article/details/82985052