⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a680ordi.cpp

📁 quarto esempi vari per c++ (schemi base)
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -