a680ordi.cpp
来自「quarto esempi vari per c++ (schemi base)」· C++ 代码 · 共 42 行
CPP
42 行
#include <iostream>
using namespace std;
void sort(long double [], int);
int main() {
const int n=400;
int i;
long double a[n];
srand(time(0));
for (i=0; i<n; i++) a[i]=i+1;
for (i=0; i<n; i++) {
int j = rand()%n;
long double t = a[i];
a[i] = a[j];
a[j] = t;
}
for (i=0; i<n; i++)
cout << a[i] << (i%20 == 19 ? "\n" : " ");
cout << "\nInizio ordinamento\n";
sort(a,n);
cout << "Fine ordinamento. Premere Invio...\n";
cin.get();
for (i=0; i<n; i++)
cout << a[i] << (i%20 == 19 ? "\n" : " ");
}
void sort(long double a[], int n) {
for (int i=0; i<n-1; i++)
for (int j=i+1; j<n; j++)
if (a[j] < a[i]) {
// sposto long double (12 byte)
long double t = a[i];
a[i] = a[j];
a[j] = t;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?