fork download
  1.  
  2. int n = 5;
  3. int a[n] = {4,3,5,1,2};
  4. int t,i,j,k;
  5.  
  6. for (i = 1; i < n; i++) {
  7. for (k = 0; k < n; k++)
  8. cout << a[k] << " ";
  9. cout << endl;
  10.  
  11. for (j = 0; j < n-i; j++) {
  12. if (a[j] < a[j+1]) {
  13. t = a[j];
  14. a[j] = a[j+1];
  15. a[j+1] = t;
  16. }
  17. }
  18. }
  19. cout << "排列好的陣列為" << endl;
  20. for (i = 0; i < n; i++)
  21. cout << a[i] << " ";
Compilation error #stdin compilation error #stdout 0s 5512KB
stdin
Standard input is empty
compilation info
prog.cpp:3:9: error: array bound is not an integer constant before ‘]’ token
  int a[n] = {4,3,5,1,2};
         ^
prog.cpp:6:2: error: expected unqualified-id before ‘for’
  for (i = 1; i < n; i++) {
  ^~~
prog.cpp:6:14: error: ‘i’ does not name a type
  for (i = 1; i < n; i++) {
              ^
prog.cpp:6:21: error: ‘i’ does not name a type
  for (i = 1; i < n; i++) {
                     ^
prog.cpp:19:2: error: ‘cout’ does not name a type
  cout << "排列好的陣列為" << endl;
  ^~~~
prog.cpp:20:2: error: expected unqualified-id before ‘for’
  for (i = 0; i < n; i++)
  ^~~
prog.cpp:20:14: error: ‘i’ does not name a type
  for (i = 0; i < n; i++)
              ^
prog.cpp:20:21: error: ‘i’ does not name a type
  for (i = 0; i < n; i++)
                     ^
stdout
Standard output is empty